summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-07-06 15:37:55 +0800
committerPeng Wu <alexepico@gmail.com>2016-07-06 15:37:55 +0800
commitf7a44387af9407d3d9d3224b5eec5077fe141445 (patch)
tree54fc03de98f9360594bd80b16e8b4dc96c835656
parentbc906ecfbf52f98fa7174cb991e2ccb67293f2e6 (diff)
downloadlibpinyin-f7a44387af9407d3d9d3224b5eec5077fe141445.tar.gz
libpinyin-f7a44387af9407d3d9d3224b5eec5077fe141445.tar.xz
libpinyin-f7a44387af9407d3d9d3224b5eec5077fe141445.zip
fixes empty input
-rw-r--r--src/lookup/pinyin_lookup2.cpp3
-rw-r--r--src/pinyin.cpp15
-rw-r--r--src/storage/phonetic_key_matrix.cpp10
3 files changed, 28 insertions, 0 deletions
diff --git a/src/lookup/pinyin_lookup2.cpp b/src/lookup/pinyin_lookup2.cpp
index 6973ecd..42bbd0e 100644
--- a/src/lookup/pinyin_lookup2.cpp
+++ b/src/lookup/pinyin_lookup2.cpp
@@ -222,7 +222,10 @@ bool PinyinLookup2::get_best_match(TokenVector prefixes,
MatchResults & results){
m_constraints = constraints;
m_matrix = matrix;
+
int nstep = m_matrix->size();
+ if (0 == nstep)
+ return false;
clear_steps(m_steps_index, m_steps_content);
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index b3ca636..414cd38 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2555,6 +2555,11 @@ bool pinyin_get_full_pinyin_auxiliary_text(pinyin_instance_t * instance,
size_t cursor,
gchar ** aux_text) {
PhoneticKeyMatrix & matrix = instance->m_matrix;
+ if (0 == matrix.size()) {
+ *aux_text = g_strdup("");
+ return false;
+ }
+
gchar * prefix = _get_aux_text_prefix
(instance, cursor, IS_PINYIN);
gchar * postfix = _get_aux_text_postfix
@@ -2608,6 +2613,11 @@ bool pinyin_get_double_pinyin_auxiliary_text(pinyin_instance_t * instance,
size_t cursor,
gchar ** aux_text) {
PhoneticKeyMatrix & matrix = instance->m_matrix;
+ if (0 == matrix.size()) {
+ *aux_text = g_strdup("");
+ return false;
+ }
+
gchar * prefix = _get_aux_text_prefix
(instance, cursor, IS_PINYIN);
gchar * postfix = _get_aux_text_postfix
@@ -2680,6 +2690,11 @@ bool pinyin_get_chewing_auxiliary_text(pinyin_instance_t * instance,
size_t cursor,
gchar ** aux_text) {
PhoneticKeyMatrix & matrix = instance->m_matrix;
+ if (0 == matrix.size()) {
+ *aux_text = g_strdup("");
+ return false;
+ }
+
gchar * prefix = _get_aux_text_prefix
(instance, cursor, IS_ZHUYIN);
gchar * postfix = _get_aux_text_postfix
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp
index 5b6ec5b..856738f 100644
--- a/src/storage/phonetic_key_matrix.cpp
+++ b/src/storage/phonetic_key_matrix.cpp
@@ -30,7 +30,11 @@ namespace pinyin{
bool fill_matrix(PhoneticKeyMatrix * matrix,
ChewingKeyVector keys,
ChewingKeyRestVector key_rests) {
+ matrix->clear_all();
+
assert(keys->len == key_rests->len);
+ if (0 == keys->len)
+ return false;
const ChewingKey * key = NULL;
const ChewingKeyRest * key_rest = NULL;
@@ -79,6 +83,8 @@ bool resplit_step(pinyin_option_t options,
return false;
size_t length = matrix->size();
+ if (0 == length)
+ return false;
GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey));
GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest));
@@ -159,6 +165,8 @@ bool inner_split_step(pinyin_option_t options,
return false;
size_t length = matrix->size();
+ if (0 == length)
+ return false;
GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey));
GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest));
@@ -214,6 +222,8 @@ bool fuzzy_syllable_step(pinyin_option_t options,
return false;
size_t length = matrix->size();
+ if (0 == length)
+ return false;
GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey));
GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest));