From 373affdcdcef75ef2d10c427221e0c17fa8a3b7f Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 26 Mar 2013 10:22:55 +0800 Subject: add checks for add phrase function --- src/pinyin.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 7462c8e..1c31b1a 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -345,12 +345,15 @@ bool pinyin_iterator_add_phrase(import_iterator_t * iter, FacadeChewingTable * & pinyin_table = context->m_pinyin_table; FacadePhraseIndex * & phrase_index = context->m_phrase_index; + bool result = false; + + if (NULL == pinyin) + return result; + /* check whether the phrase exists in phrase table */ glong len_phrase = 0; ucs4_t * ucs4_phrase = g_utf8_to_ucs4(phrase, -1, NULL, &len_phrase, NULL); - bool result = false; - pinyin_option_t options = PINYIN_CORRECT_ALL | USE_TONE; FullPinyinParser2 parser; ChewingKeyVector keys = @@ -364,7 +367,7 @@ bool pinyin_iterator_add_phrase(import_iterator_t * iter, if (len_phrase != keys->len) return result; - if (len_phrase >= MAX_PHRASE_LENGTH) + if (0 == len_phrase || len_phrase >= MAX_PHRASE_LENGTH) return result; phrase_token_t token = null_token; -- cgit