From bd771b0c51f35c6ab6377719ab654370782ef1c9 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 18 Apr 2013 10:23:49 +0800 Subject: support two letter yunmu from full pinyin --- scripts/pinyin.py | 3 +- src/storage/double_pinyin_table.h | 4 +-- src/storage/pinyin_parser2.cpp | 60 +++++++++++++++++++++++++-------------- 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; -- cgit