diff options
author | Peng Wu <alexepico@gmail.com> | 2013-09-24 10:50:18 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-09-24 10:50:18 +0800 |
commit | d6839ba44930779be257ecf1f3bfb756725432f0 (patch) | |
tree | 8343f2a64463832c942c9ac52cd737ee3cf10255 | |
parent | ea941848955cc1c3fed28c3126a593a572afaf8b (diff) | |
download | libzhuyin-d6839ba44930779be257ecf1f3bfb756725432f0.tar.gz libzhuyin-d6839ba44930779be257ecf1f3bfb756725432f0.tar.xz libzhuyin-d6839ba44930779be257ecf1f3bfb756725432f0.zip |
improves parse method
-rw-r--r-- | src/storage/pinyin_parser2.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index e7c8a71..b636117 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -957,12 +957,14 @@ int ChewingDaChenCP26Parser2::parse(pinyin_option_t options, /* maximum forward match for chewing. */ int parsed_len = 0; + const char * cur_str = NULL; + ChewingKey key; ChewingKeyRest key_rest; + while (parsed_len < maximum_len) { - const char * cur_str = str + parsed_len; + cur_str = str + parsed_len; i = std_lite::min(maximum_len - parsed_len, (int)max_chewing_dachen26_length); - ChewingKey key; ChewingKeyRest key_rest; for (; i > 0; --i) { bool success = parse_one_key(options, key, cur_str, i); if (success) @@ -980,6 +982,27 @@ int ChewingDaChenCP26Parser2::parse(pinyin_option_t options, g_array_append_val(key_rests, key_rest); } + /* for the last partial input */ + options |= CHEWING_INCOMPLETE; + + cur_str = str + parsed_len; + i = std_lite::min(maximum_len - parsed_len, + (int) max_chewing_dachen26_length); + for (; i > 0; --i) { + bool success = parse_one_key(options, key, cur_str, i); + if (success) + break; + } + + if (i > 0) { /* found one */ + key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i; + parsed_len += i; + + /* save the pinyin. */ + g_array_append_val(keys, key); + g_array_append_val(key_rests, key_rest); + } + return parsed_len; } |