diff options
author | Hiroshi Sumita <hsumita@chromium.org> | 2012-05-25 21:20:15 +0900 |
---|---|---|
committer | Hiroshi Sumita <hsumita@chromium.org> | 2012-05-25 21:20:15 +0900 |
commit | 1b0f6aab98c479873a278b50fce1ff673e3d6564 (patch) | |
tree | d1906bef6b601237b8b2839bfc3adc649fab550a | |
parent | f8c1629396ce529d6c5f3230e5437ae6da164262 (diff) | |
download | pyzy-1b0f6aab98c479873a278b50fce1ff673e3d6564.tar.gz |
Fixes 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/6250045
-rw-r--r-- | src/PyZyDoublePinyinContext.cc | 81 | ||||
-rw-r--r-- | src/PyZyPinyinParser.cc | 2 |
2 files changed, 49 insertions, 34 deletions
diff --git a/src/PyZyDoublePinyinContext.cc b/src/PyZyDoublePinyinContext.cc index 8a68fee..7788f75 100644 --- a/src/PyZyDoublePinyinContext.cc +++ b/src/PyZyDoublePinyinContext.cc @@ -342,48 +342,63 @@ DoublePinyinContext::isPinyin (int i) inline const Pinyin * DoublePinyinContext::isPinyin (int i, int j) { - const Pinyin *pinyin; + const Pinyin *pinyin = NULL; char sheng = ID_TO_SHENG (i); const char *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 bool diff --git a/src/PyZyPinyinParser.cc b/src/PyZyPinyinParser.cc index 051e73a..ef8d635 100644 --- a/src/PyZyPinyinParser.cc +++ b/src/PyZyPinyinParser.cc @@ -309,7 +309,7 @@ PinyinParser::parseBopomofo (const std::wstring &bopomofo, { std::wstring::const_iterator bpmf = bopomofo.begin(); const std::wstring::const_iterator end = bpmf + len; - const Pinyin **bs_res; + const Pinyin **bs_res = NULL; wchar_t buf[MAX_BOPOMOFO_LEN + 1]; size_t i, j; |