summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/pinyin.cpp15
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