From 0e1f4a854482344e08fecbed9efe404063158d74 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Mon, 3 May 2010 15:08:59 +0800 Subject: [PATCH] Fix problem in parse double pinyin --- src/DoublePinyinEditor.cc | 15 ++++++++++----- src/PinyinParser.cc | 32 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/DoublePinyinEditor.cc b/src/DoublePinyinEditor.cc index ed9e339..e0cf109 100644 --- a/src/DoublePinyinEditor.cc +++ b/src/DoublePinyinEditor.cc @@ -344,17 +344,22 @@ DoublePinyinEditor::isPinyin (gint i, gint j) return pinyin; /* if sheng == j q x y and yun == v, try to correct v to u */ + if ((Config::option () & PINYIN_CORRECT_V_TO_U) == 0) + return NULL; + + if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V) + return NULL; + switch (sheng) { case PINYIN_ID_J: case PINYIN_ID_Q: case PINYIN_ID_X: case PINYIN_ID_Y: - if (yun[0] == PINYIN_ID_V || yun[1] == PINYIN_ID_V) { - pinyin = PinyinParser::isPinyin (sheng, PINYIN_ID_V, - Config::option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_ALL)); - } + return PinyinParser::isPinyin (sheng, PINYIN_ID_V, + Config::option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); + default: + return NULL; } - return pinyin; } inline gboolean diff --git a/src/PinyinParser.cc b/src/PinyinParser.cc index 8d269c0..d6d1e3e 100644 --- a/src/PinyinParser.cc +++ b/src/PinyinParser.cc @@ -1,4 +1,5 @@ /* vim:set et sts=4: */ + #include #include #include @@ -208,7 +209,8 @@ PinyinParser::parse (const String &pinyin, return p - (const gchar *)pinyin; } -static const gchar *id_map[] = { +static const gchar * const +id_map[] = { "", "b", "c", "ch", "d", "f", "g", "h", "j", "k", "l", "m", @@ -221,17 +223,35 @@ static const gchar *id_map[] = { "ie", "in", "ing", "iong", "iu", "o", "ong", "ou", "u", "ua", "uai", "uan", "uang", - "ue", "ui", "un", "uo", "v" + 0, /* it should be ue or ve */ + "ui", "un", "uo", "v" }; const Pinyin * PinyinParser::isPinyin (gint sheng, gint yun, guint option) { const Pinyin *result; - gchar buf[8]; - - g_strlcpy (buf, id_map[sheng], sizeof (buf)); - g_strlcat (buf, id_map[yun], sizeof (buf)); + gchar buf[16]; + + std::strcpy (buf, id_map[sheng]); + + if (yun == PINYIN_ID_UE) { + /* append ue or ve base on sheng */ + switch (sheng) { + case PINYIN_ID_J: + case PINYIN_ID_Q: + case PINYIN_ID_X: + case PINYIN_ID_Y: + std::strcat (buf, "ue"); + break; + default: + std::strcat (buf, "ve"); + break; + } + } + else { + std::strcat (buf, id_map[yun]); + } result = (const Pinyin *) bsearch (buf, pinyin_table, G_N_ELEMENTS (pinyin_table), sizeof (Pinyin), py_cmp); -- 2.7.4