diff options
author | Peng Wu <alexepico@gmail.com> | 2021-05-17 15:14:11 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2021-05-17 15:14:11 +0800 |
commit | a4bee4593faad577c85fa2d7296da480966bd8a7 (patch) | |
tree | a97b43f1503a025ed40e3aaf5de28da7ee40ac54 /src | |
parent | f12961453c16846b9902a339bf2ff44139ab5f7e (diff) | |
download | libpinyin-a4bee4593faad577c85fa2d7296da480966bd8a7.tar.gz libpinyin-a4bee4593faad577c85fa2d7296da480966bd8a7.tar.xz libpinyin-a4bee4593faad577c85fa2d7296da480966bd8a7.zip |
Improve pinyin_remember_user_input function
Diffstat (limited to 'src')
-rw-r--r-- | src/pinyin.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 4e8756c..bfa1993 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -3122,8 +3122,10 @@ static bool _remember_phrase_recur(pinyin_instance_t * instance, return false; /* as cached_keys and phrase has the same length. */ - assert(cached_keys->len > 0); - assert(cached_keys->len <= MAX_PHRASE_LENGTH); + if (cached_keys->len <= 0) + return false; + if (cached_keys->len > MAX_PHRASE_LENGTH) + return false; return _add_phrase(context, index, cached_keys, phrase, phrase_length, count); @@ -3131,7 +3133,8 @@ static bool _remember_phrase_recur(pinyin_instance_t * instance, const size_t size = matrix.get_column_size(start); /* assume pinyin parsers will filter invalid keys. */ - assert(size > 0); + if (size <= 0) + return false; bool result = false; @@ -3145,7 +3148,9 @@ static bool _remember_phrase_recur(pinyin_instance_t * instance, const ChewingKey zero_key; if (zero_key == key) { /* assume only one key here for "'" or the last key. */ - assert(1 == size); + if (1 != size) + return false; + return _remember_phrase_recur (instance, cached_keys, cached_tokens, newstart, phrase, count); @@ -3212,7 +3217,8 @@ bool pinyin_remember_user_input(pinyin_instance_t * instance, return false; } - assert(cached_tokens->len == phrase_length); + if (cached_tokens->len != phrase_length) + return false; ChewingKeyVector cached_keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); |