Commit 1b0f6aab authored by Hiroshi Sumita's avatar Hiroshi Sumita
Browse files

Fixes double pinyin parse error when fuzzy pinyin is enabled.

parent f8c16293
Loading
Loading
Loading
Loading
+48 −33
Original line number Diff line number Diff line
@@ -342,49 +342,64 @@ 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);

    do {
        if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID)
        return NULL;
            break;

        if (sheng == PINYIN_ID_ZERO && yun[0] == PINYIN_ID_ZERO)
        return NULL;
            break;

        if (yun[1] == PINYIN_ID_VOID) {
        return PinyinParser::isPinyin (
            pinyin = PinyinParser::isPinyin (
                sheng, yun[0],
                m_config.option & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
            break;
        }

        // Check sheng + yun[0] without all fuzzy pinyin options
        pinyin = PinyinParser::isPinyin(sheng, yun[0], 0);
        if (pinyin != NULL)
            break;

        // Check sheng + yun[1] without all fuzzy pinyin options
        pinyin = PinyinParser::isPinyin(sheng, yun[1], 0);
        if (pinyin != NULL)
            break;

        pinyin = PinyinParser::isPinyin (
            sheng, yun[0], m_config.option & (PINYIN_FUZZY_ALL));
    if (pinyin == NULL)
        if (pinyin != NULL)
            break;

        pinyin = PinyinParser::isPinyin (
            sheng, yun[1], m_config.option & (PINYIN_FUZZY_ALL));
        if (pinyin != NULL)
        return pinyin;
          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;

    if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V)
        return NULL;
            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:
        return PinyinParser::isPinyin (
                pinyin = PinyinParser::isPinyin (
                    sheng, PINYIN_ID_V,
            m_config.option & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
    default:
        return NULL;
                    m_config.option & (
                        PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U));
            }
        }
    } while (false);

    return pinyin;
}

inline bool
DoublePinyinContext::updatePinyin (bool all)
+1 −1
Original line number Diff line number Diff line
@@ -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;