summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-04-18 10:23:49 +0800
committerPeng Wu <alexepico@gmail.com>2013-04-18 11:02:59 +0800
commitbd771b0c51f35c6ab6377719ab654370782ef1c9 (patch)
treedd8fcfd7c87a25d23613ef8107b66ccda04d8e2e
parent29ba511009f6346e0350735d342b81de56336b6b (diff)
downloadlibpinyin-bd771b0c51f35c6ab6377719ab654370782ef1c9.tar.gz
libpinyin-bd771b0c51f35c6ab6377719ab654370782ef1c9.tar.xz
libpinyin-bd771b0c51f35c6ab6377719ab654370782ef1c9.zip
support two letter yunmu from full pinyin
-rw-r--r--scripts/pinyin.py3
-rw-r--r--src/storage/double_pinyin_table.h4
-rw-r--r--src/storage/pinyin_parser2.cpp60
3 files changed, 42 insertions, 25 deletions
diff --git a/scripts/pinyin.py b/scripts/pinyin.py
index 174fdde..dd0e156 100644
--- a/scripts/pinyin.py
+++ b/scripts/pinyin.py
@@ -356,7 +356,8 @@ XHE_SHUANGPIN_SHENGMU_DICT = {
"h" : "h", "i" : "ch", "j" : "j", "k" : "k", "l" : "l",
"m" : "m", "n" : "n", "o" : "'", "p" : "p", "q" : "q",
"r" : "r", "s" : "s", "t" : "t", "u" : "sh", "v" : "zh",
- "w" : "w", "x" : "x", "y" : "y", "z" : "z"
+ "w" : "w", "x" : "x", "y" : "y", "z" : "z",
+ "a" : "'", "e" : "'"
}
XHE_SHUANGPIN_YUNMU_DICT = {
diff --git a/src/storage/double_pinyin_table.h b/src/storage/double_pinyin_table.h
index 6af66b7..52af618 100644
--- a/src/storage/double_pinyin_table.h
+++ b/src/storage/double_pinyin_table.h
@@ -307,11 +307,11 @@ const double_pinyin_scheme_yunmu_item_t double_pinyin_pyjj_yun[] = {
};
const double_pinyin_scheme_shengmu_item_t double_pinyin_xhe_sheng[] = {
-{NULL } /* A */,
+{"'" } /* A */,
{"b" } /* B */,
{"c" } /* C */,
{"d" } /* D */,
-{NULL } /* E */,
+{"'" } /* E */,
{"f" } /* F */,
{"g" } /* G */,
{"h" } /* H */,
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index b8e603f..5d406ae 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -682,7 +682,7 @@ bool DoublePinyinParser2::parse_one_key(pinyin_option_t options,
const char * sheng = m_shengmu_table[charid].m_shengmu;
if (NULL == sheng)
return false;
- if (strcmp(sheng, "'") == 0)
+ if (0 == strcmp(sheng, "'"))
sheng = "";
/* parse yunmu here. */
@@ -690,33 +690,49 @@ bool DoublePinyinParser2::parse_one_key(pinyin_option_t options,
if (!IS_KEY(ch))
return false;
- charid = ch == ';' ? 26 : ch - 'a';
- /* first yunmu */
- const char * yun = m_yunmu_table[charid].m_yunmus[0];
- if (NULL == yun)
- return false;
+ gchar * pinyin = NULL;
+ do {
+
+ charid = ch == ';' ? 26 : ch - 'a';
+ /* first yunmu */
+ const char * yun = m_yunmu_table[charid].m_yunmus[0];
+ if (NULL == yun)
+ break;
- gchar * pinyin = g_strdup_printf("%s%s", sheng, yun);
- if (search_pinyin_index(options, pinyin, key)) {
- key.m_tone = tone;
+ pinyin = g_strdup_printf("%s%s", sheng, yun);
+ if (search_pinyin_index(options, pinyin, key)) {
+ key.m_tone = tone;
+ g_free(pinyin);
+ return true;
+ }
g_free(pinyin);
- return true;
- }
- g_free(pinyin);
- /* second yunmu */
- yun = m_yunmu_table[charid].m_yunmus[1];
- if (NULL == yun)
- return false;
+ /* second yunmu */
+ yun = m_yunmu_table[charid].m_yunmus[1];
+ if (NULL == yun)
+ break;
- pinyin = g_strdup_printf("%s%s", sheng, yun);
- if (search_pinyin_index(options, pinyin, key)) {
- key.m_tone = tone;
+ pinyin = g_strdup_printf("%s%s", sheng, yun);
+ if (search_pinyin_index(options, pinyin, key)) {
+ key.m_tone = tone;
+ g_free(pinyin);
+ return true;
+ }
g_free(pinyin);
- return true;
- }
- g_free(pinyin);
+ } while(0);
+#if 1
+ /* support two letter yunmu from full pinyin */
+ if (0 == strcmp(sheng, "")) {
+ pinyin = g_strndup(str, 2);
+ if (search_pinyin_index(options, pinyin, key)) {
+ key.m_tone = tone;
+ g_free(pinyin);
+ return true;
+ }
+ g_free(pinyin);
+ }
+#endif
}
return false;