summaryrefslogtreecommitdiffstats
path: root/src/storage/zhuyin_parser2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/zhuyin_parser2.cpp')
-rw-r--r--src/storage/zhuyin_parser2.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/storage/zhuyin_parser2.cpp b/src/storage/zhuyin_parser2.cpp
index 9ae7fbd..e711b76 100644
--- a/src/storage/zhuyin_parser2.cpp
+++ b/src/storage/zhuyin_parser2.cpp
@@ -160,6 +160,7 @@ static int search_chewing_symbols2(const zhuyin_symbol_item_t * symbol_table,
bool ZhuyinSimpleParser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
+ gint16 & distance,
const char * str, int len) const {
options &= ~PINYIN_AMB_ALL;
unsigned char tone = CHEWING_ZERO_TONE;
@@ -240,9 +241,10 @@ int ZhuyinSimpleParser2::parse(pinyin_option_t options,
i = std_lite::min(maximum_len - parsed_len,
(int)max_chewing_length);
+ gint16 distance = 0;
ChewingKey key; ChewingKeyRest key_rest;
for (; i > 0; --i) {
- bool success = parse_one_key(options, key, cur_str, i);
+ bool success = parse_one_key(options, key, distance, cur_str, i);
if (success)
break;
}
@@ -250,6 +252,9 @@ int ZhuyinSimpleParser2::parse(pinyin_option_t options,
if (0 == i) /* no more possible chewings. */
break;
+ if (!key.is_valid_zhuyin())
+ break;
+
key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
parsed_len += i;
@@ -328,6 +333,7 @@ bool ZhuyinSimpleParser2::in_chewing_scheme(pinyin_option_t options,
bool ZhuyinDiscreteParser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
+ gint16 & distance,
const char * str, int len) const {
if (0 == len)
return false;
@@ -427,9 +433,10 @@ int ZhuyinDiscreteParser2::parse(pinyin_option_t options,
i = std_lite::min(maximum_len - parsed_len,
(int)max_chewing_length);
+ gint16 distance = 0;
ChewingKey key; ChewingKeyRest key_rest;
for (; i > 0; --i) {
- bool success = parse_one_key(options, key, cur_str, i);
+ bool success = parse_one_key(options, key, distance, cur_str, i);
if (success)
break;
}
@@ -437,6 +444,9 @@ int ZhuyinDiscreteParser2::parse(pinyin_option_t options,
if (0 == i) /* no more possible chewings. */
break;
+ if (!key.is_valid_zhuyin())
+ break;
+
key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
parsed_len += i;
@@ -561,6 +571,7 @@ static int count_same_chars(const char * str, int len) {
bool ZhuyinDaChenCP26Parser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
+ gint16 & distance,
const char *str, int len) const {
if (0 == len)
return false;
@@ -725,15 +736,16 @@ int ZhuyinDaChenCP26Parser2::parse(pinyin_option_t options,
/* maximum forward match for chewing. */
int parsed_len = 0;
const char * cur_str = NULL;
- ChewingKey key; ChewingKeyRest key_rest;
while (parsed_len < maximum_len) {
cur_str = str + parsed_len;
i = std_lite::min(maximum_len - parsed_len,
(int)max_chewing_dachen26_length);
+ gint16 distance = 0;
+ ChewingKey key; ChewingKeyRest key_rest;
for (; i > 0; --i) {
- bool success = parse_one_key(options, key, cur_str, i);
+ bool success = parse_one_key(options, key, distance, cur_str, i);
if (success)
break;
}
@@ -741,6 +753,9 @@ int ZhuyinDaChenCP26Parser2::parse(pinyin_option_t options,
if (0 == i) /* no more possible chewings. */
break;
+ if (!key.is_valid_zhuyin())
+ break;
+
key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
parsed_len += i;
@@ -762,6 +777,9 @@ int ZhuyinDaChenCP26Parser2::parse(pinyin_option_t options,
break;
}
+ if (!key.is_valid_zhuyin())
+ return parsed_len;
+
if (i > 0) { /* found one */
key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i;
parsed_len += i;
@@ -839,6 +857,7 @@ ZhuyinDirectParser2::ZhuyinDirectParser2 (){
bool ZhuyinDirectParser2::parse_one_key(pinyin_option_t options,
ChewingKey & key,
+ gint16 & distance,
const char *str, int len) const {
options &= ~PINYIN_AMB_ALL;
/* by default, chewing will use the first tone. */
@@ -898,8 +917,6 @@ int ZhuyinDirectParser2::parse(pinyin_option_t options,
g_array_set_size(keys, 0);
g_array_set_size(key_rests, 0);
- ChewingKey key; ChewingKeyRest key_rest;
-
int parsed_len = 0;
int i = 0, cur = 0, next = 0;
while (cur < len) {
@@ -910,7 +927,16 @@ int ZhuyinDirectParser2::parse(pinyin_option_t options,
}
next = i;
- if (parse_one_key(options, key, str + cur, next - cur)) {
+ gint16 distance = 0;
+ ChewingKey key; ChewingKeyRest key_rest;
+ if (parse_one_key(options, key, distance, str + cur, next - cur)) {
+#if 0
+ /* as direct parser handles data source,
+ assume the data is correct when loading. */
+ if (!key.is_valid_zhuyin())
+ return parsed_len;
+#endif
+
key_rest.m_raw_begin = cur; key_rest.m_raw_end = next;
/* save the pinyin. */