diff options
author | Peng Wu <alexepico@gmail.com> | 2015-10-13 15:45:01 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-10-13 15:45:01 +0800 |
commit | 390a0c0959500de088783273fda4341e0644c24e (patch) | |
tree | b3fdeb7dfa8a5826a9886524cdd560c1b252784a /src | |
parent | 3264d488a3d21bdc3abc0b23a8fb1ea9e2a88e35 (diff) | |
download | libpinyin-390a0c0959500de088783273fda4341e0644c24e.tar.gz libpinyin-390a0c0959500de088783273fda4341e0644c24e.tar.xz libpinyin-390a0c0959500de088783273fda4341e0644c24e.zip |
support force tone in pinyin parsers
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/pinyin_parser2.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index 60a50d0..85988e6 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -242,6 +242,12 @@ bool FullPinyinParser2::parse_one_key (pinyin_option_t options, parsed_len --; tone_pos = parsed_len; } + + /* check the force tone option. */ + if (options & FORCE_TONE && CHEWING_ZERO_TONE == tone) { + g_free(input); + return false; + } } /* parse pinyin core staff here. */ @@ -638,6 +644,10 @@ bool DoublePinyinParser2::parse_one_key(pinyin_option_t options, const char *str, int len) const { options &= ~(PINYIN_CORRECT_ALL|PINYIN_AMB_ALL); + /* force tone requires at least 3 characters. */ + if (options & FORCE_TONE && 3 != len) + return false; + if (1 == len) { if (!(options & PINYIN_INCOMPLETE)) return false; @@ -651,11 +661,10 @@ bool DoublePinyinParser2::parse_one_key(pinyin_option_t options, if (NULL == sheng || strcmp(sheng, "'") == 0) return false; - if (search_pinyin_index(options, sheng, key)) { + if (search_pinyin_index(options, sheng, key)) return true; - } else { + else return false; - } } ChewingTone tone = CHEWING_ZERO_TONE; @@ -670,6 +679,10 @@ bool DoublePinyinParser2::parse_one_key(pinyin_option_t options, if (!('0' < ch && ch <= '5')) return false; tone = (ChewingTone) (ch - '0'); + + /* check the force tone option. */ + if (options & FORCE_TONE && CHEWING_ZERO_TONE == tone) + return false; } if (2 == len || 3 == len) { |