summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Huang <shawn.p.huang@gmail.com>2012-05-23 08:03:39 -0400
committerPeng Huang <shawn.p.huang@gmail.com>2012-05-23 08:03:39 -0400
commit2ac12b8973c11b40e569bb952d1e21d03e5ce6ef (patch)
tree3a930195789272567fcc28ad1498db9dad7366ca
parentb2dd07991eba77c56c12920182e8c9d5553b612f (diff)
downloadibus-pinyin-2ac12b8973c11b40e569bb952d1e21d03e5ce6ef.tar.gz
Fix double pinyin parse error when fuzzy pinyin is enabled.
BUG=http://code.google.com/p/ibus/issues/detail?id=1441 TEST=Manually Review URL: https://codereview.appspot.com/6221060
-rw-r--r--src/PYDoublePinyinEditor.cc78
1 files changed, 47 insertions, 31 deletions
diff --git a/src/PYDoublePinyinEditor.cc b/src/PYDoublePinyinEditor.cc
index fb775d9..cc60a2e 100644
--- a/src/PYDoublePinyinEditor.cc
+++ b/src/PYDoublePinyinEditor.cc
@@ -341,46 +341,62 @@ DoublePinyinEditor::isPinyin (gint i)
inline const Pinyin *
DoublePinyinEditor::isPinyin (gint i, gint j)
{
- const Pinyin *pinyin;
+ const Pinyin *pinyin = NULL;
gint8 sheng = ID_TO_SHENG (i);
const gint8 *yun = ID_TO_YUNS (j);
- if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID)
- return NULL;
+ do {
+ if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID)
+ break;
- if (sheng == PINYIN_ID_ZERO && yun[0] == PINYIN_ID_ZERO)
- return NULL;
+ if (sheng == PINYIN_ID_ZERO && yun[0] == PINYIN_ID_ZERO)
+ break;
- if (yun[1] == PINYIN_ID_VOID) {
- return PinyinParser::isPinyin (sheng, yun[0],
- m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
- }
+ if (yun[1] == PINYIN_ID_VOID) {
+ pinyin = PinyinParser::isPinyin (sheng, yun[0],
+ m_config.option () &
+ (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
+ break;
+ }
- pinyin = PinyinParser::isPinyin (sheng, yun[0],
- m_config.option () & (PINYIN_FUZZY_ALL));
- if (pinyin == NULL)
- pinyin = PinyinParser::isPinyin (sheng, yun[1],
- m_config.option () & (PINYIN_FUZZY_ALL));
- if (pinyin != NULL)
- return pinyin;
+ // Check sheng + yun[0] without all fuzzy pinyin options
+ pinyin = PinyinParser::isPinyin(sheng, yun[0], 0);
+ if (pinyin != NULL)
+ break;
- /* if sheng == j q x y and yun == v, try to correct v to u */
- if ((m_config.option () & PINYIN_CORRECT_V_TO_U) == 0)
- return NULL;
+ // Check sheng + yun[1] without all fuzzy pinyin options
+ pinyin = PinyinParser::isPinyin(sheng, yun[1], 0);
+ if (pinyin != NULL)
+ break;
- if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V)
- return NULL;
+ pinyin = PinyinParser::isPinyin (sheng, yun[0],
+ m_config.option () & (PINYIN_FUZZY_ALL));
+ if (pinyin != NULL)
+ break;
- switch (sheng) {
- case PINYIN_ID_J:
- case PINYIN_ID_Q:
- case PINYIN_ID_X:
- case PINYIN_ID_Y:
- return PinyinParser::isPinyin (sheng, PINYIN_ID_V,
- m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
- default:
- return NULL;
- }
+ pinyin = PinyinParser::isPinyin (sheng, yun[1],
+ m_config.option () & (PINYIN_FUZZY_ALL));
+ if (pinyin != NULL)
+ break;
+
+ /* if sheng == j q x y and yun == v, try to correct v to u */
+ if ((m_config.option () & PINYIN_CORRECT_V_TO_U) == 0)
+ break;
+
+ if (yun[0] == PINYIN_ID_V || yun[1] == PINYIN_ID_V) {
+ switch (sheng) {
+ case PINYIN_ID_J:
+ case PINYIN_ID_Q:
+ case PINYIN_ID_X:
+ case PINYIN_ID_Y:
+ pinyin = PinyinParser::isPinyin (sheng, PINYIN_ID_V,
+ m_config.option () &
+ (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
+ }
+ }
+ } while (false);
+
+ return pinyin;
}
inline gboolean