summaryrefslogtreecommitdiffstats
path: root/src/storage/pinyin_parser2.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-12-21 12:20:18 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-21 12:20:18 +0800
commitda0c48d52aad4541d38d45ad3490b151029b7f26 (patch)
tree77f0a8757282645708a7f3623c277d1d17db4dfd /src/storage/pinyin_parser2.cpp
parentb381ab0f9d3aa3a607403f4981f32911869ea62e (diff)
downloadlibpinyin-da0c48d52aad4541d38d45ad3490b151029b7f26.tar.gz
libpinyin-da0c48d52aad4541d38d45ad3490b151029b7f26.tar.xz
libpinyin-da0c48d52aad4541d38d45ad3490b151029b7f26.zip
re-factor code
Diffstat (limited to 'src/storage/pinyin_parser2.cpp')
-rw-r--r--src/storage/pinyin_parser2.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index a762909..bab9d8a 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -662,12 +662,12 @@ bool DoublePinyinParser2::set_scheme(DoublePinyinScheme scheme) {
/* the chewing string must be freed with g_free. */
static bool search_chewing_symbols(const chewing_symbol_item_t * symbol_table,
- const char key, char ** chewing) {
+ const char key, const char ** chewing) {
*chewing = NULL;
/* just iterate the table, as we only have < 50 items. */
while (symbol_table->m_input != '\0') {
if (symbol_table->m_input == key) {
- *chewing = g_strdup(symbol_table->m_chewing);
+ *chewing = symbol_table->m_chewing;
return true;
}
symbol_table ++;
@@ -705,12 +705,11 @@ bool ChewingParser2::parse_one_key(pinyin_option_t options,
}
int i;
- gchar * chewing = NULL, * onechar = NULL;
+ gchar * chewing = NULL; const char * onechar = NULL;
/* probe the possible chewing map in the rest of str. */
for (i = 0; i < symbols_len; ++i) {
if (!search_chewing_symbols(m_symbol_table, str[i], &onechar)) {
- g_free(onechar);
g_free(chewing);
return false;
}
@@ -722,7 +721,6 @@ bool ChewingParser2::parse_one_key(pinyin_option_t options,
chewing = g_strconcat(chewing, onechar, NULL);
g_free(tmp);
}
- g_free(onechar);
}
/* search the chewing in the chewing index table. */
@@ -748,7 +746,7 @@ int ChewingParser2::parse(pinyin_option_t options, ChewingKeyVector & keys,
int maximum_len = 0; int i;
/* probe the longest possible chewing string. */
for (i = 0; i < len; ++i) {
- if (!in_chewing_scheme(str[i]))
+ if (!in_chewing_scheme(str[i], NULL))
break;
}
maximum_len = i;
@@ -806,13 +804,21 @@ bool ChewingParser2::set_scheme(ChewingScheme scheme) {
}
-bool ChewingParser2::in_chewing_scheme(const char key) const {
- gchar * chewing = NULL;
+bool ChewingParser2::in_chewing_scheme(const char key, const char ** symbol)
+ const {
+ const gchar * chewing = NULL;
char tone = CHEWING_ZERO_TONE;
- bool retval = search_chewing_symbols(m_symbol_table, key, &chewing) ||
- search_chewing_tones(m_tone_table, key, &tone);
- g_free(chewing);
+ if (search_chewing_symbols(m_symbol_table, key, &chewing)) {
+ if (symbol)
+ *symbol = chewing;
+ return true;
+ }
- return retval;
+ if (search_chewing_tones(m_tone_table, key, &tone)) {
+ if (symbol)
+ *symbol = chewing_tone_table[tone];
+ }
+
+ return false;
}