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
/* vim:set et sts=4: */
+
#include <cstring>
#include <cstdlib>
#include <glib.h>
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",
"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);