Fix problem in parse double pinyin
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 3 May 2010 07:08:59 +0000 (15:08 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 3 May 2010 07:30:47 +0000 (15:30 +0800)
src/DoublePinyinEditor.cc
src/PinyinParser.cc

index ed9e339..e0cf109 100644 (file)
@@ -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
index 8d269c0..d6d1e3e 100644 (file)
@@ -1,4 +1,5 @@
 /* vim:set et sts=4: */
+
 #include <cstring>
 #include <cstdlib>
 #include <glib.h>
@@ -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);