diff options
author | Peng Wu <alexepico@gmail.com> | 2013-09-16 13:58:22 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-09-16 13:58:22 +0800 |
commit | d17dfde1b862da432d75d799458da64000db4f43 (patch) | |
tree | 99c08aec0a20acbd0c702667219e0c2158d2599f | |
parent | 5ed605676150810da376710beddefb6af787fd55 (diff) | |
download | libzhuyin-d17dfde1b862da432d75d799458da64000db4f43.tar.gz libzhuyin-d17dfde1b862da432d75d799458da64000db4f43.tar.xz libzhuyin-d17dfde1b862da432d75d799458da64000db4f43.zip |
write parse method
-rw-r--r-- | src/storage/pinyin_parser2.cpp | 42 | ||||
-rw-r--r-- | src/storage/pinyin_parser2.h | 1 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index 98702fe..aada136 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -675,11 +675,51 @@ probe: return false; } +/* only characters in chewing keyboard scheme are accepted here. */ int ChewingDiscreteParser2::parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const { - assert(FALSE); + /* add keyboard mapping specific options. */ + options |= m_options; + + g_array_set_size(keys, 0); + g_array_set_size(key_rests, 0); + + int maximum_len = 0; int i; + /* probe the longest possible chewing string. */ + for (i = 0; i < len; ++i) { + if (!in_chewing_scheme(options, str[i], NULL)) + break; + } + maximum_len = i; + + /* maximum forward match for chewing. */ + int parsed_len = 0; + while (parsed_len < maximum_len) { + const char * cur_str = str + parsed_len; + i = std_lite::min(maximum_len - parsed_len, + (int)max_chewing_length); + + ChewingKey key; ChewingKeyRest key_rest; + for (; i > 0; --i) { + bool success = parse_one_key(options, key, cur_str, i); + if (success) + break; + } + + if (0 == i) /* no more possible chewings. */ + break; + + 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; } diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h index b410de5..16c078c 100644 --- a/src/storage/pinyin_parser2.h +++ b/src/storage/pinyin_parser2.h @@ -213,6 +213,7 @@ protected: public: ChewingDiscreteParser2() { + m_options = 0; m_chewing_index = NULL; m_chewing_index_len = 0; m_initial_table = NULL; m_middle_table = NULL; m_final_table = NULL; m_tone_table = NULL; |