diff options
author | Peng Wu <alexepico@gmail.com> | 2013-03-04 11:07:43 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-03-04 11:07:43 +0800 |
commit | b7c510534852e86e1bc7e86af652d5a3899a5682 (patch) | |
tree | c761273ac145add7fd37adbbfd7e5270b0f2ba29 | |
parent | ed506c6bdd7de47bc8bc091e39177a9852749d93 (diff) | |
download | libpinyin-b7c510534852e86e1bc7e86af652d5a3899a5682.tar.gz libpinyin-b7c510534852e86e1bc7e86af652d5a3899a5682.tar.xz libpinyin-b7c510534852e86e1bc7e86af652d5a3899a5682.zip |
fixes pinyin_iterator_add_phrase
-rw-r--r-- | src/pinyin.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 0549f7c..56d2ed5 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -325,6 +325,15 @@ bool pinyin_iterator_add_phrase(import_iterator_t * iter, ChewingKeyRestVector key_rests = g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); + /* parse the pinyin. */ + parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); + + if (len_phrase != keys->len) + return result; + + if (len_phrase >= MAX_PHRASE_LENGTH) + return result; + phrase_token_t token = null_token; GArray * tokenarray = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); @@ -366,9 +375,6 @@ bool pinyin_iterator_add_phrase(import_iterator_t * iter, assert(0 == memcmp (ucs4_phrase, tmp_phrase, sizeof(ucs4_t) * len_phrase)); - /* parse the pinyin. */ - parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); - PhraseItem * removed_item = NULL; retval = phrase_index->remove_phrase_item(token, removed_item); if (ERROR_OK == retval) { @@ -391,9 +397,6 @@ bool pinyin_iterator_add_phrase(import_iterator_t * iter, if (0x00000000 == (token & PHRASE_MASK)) token++; - /* parse the pinyin. */ - parser.parse(options, keys, key_rests, pinyin, strlen(pinyin)); - if (len_phrase == keys->len) { /* valid pinyin */ phrase_table->add_index(len_phrase, ucs4_phrase, token); pinyin_table->add_index |