diff options
author | Peng Wu <alexepico@gmail.com> | 2013-09-22 16:16:33 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2013-09-22 16:16:38 +0800 |
commit | a1ed16081569a46afce162fc3cfb2510bd6763b5 (patch) | |
tree | bfe6dd25ee4d358303b826b13a1b98dbb3425085 /src | |
parent | 69f46d03e53398ba9df3f75d939353d18ac7c4ed (diff) | |
download | libzhuyin-a1ed16081569a46afce162fc3cfb2510bd6763b5.tar.gz libzhuyin-a1ed16081569a46afce162fc3cfb2510bd6763b5.tar.xz libzhuyin-a1ed16081569a46afce162fc3cfb2510bd6763b5.zip |
begin to write ChewingDaChenCP26Parser2 class
Diffstat (limited to 'src')
-rw-r--r-- | src/storage/pinyin_parser2.cpp | 46 | ||||
-rw-r--r-- | src/storage/pinyin_parser2.h | 23 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index dde1cd2..55eba57 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -743,3 +743,49 @@ static int search_chewing_symbols2(const chewing_symbol_item_t * symbol_table, assert(0 <= num && num <= 2); return num; } + +ChewingDaChenCP26Parser2::ChewingDaChenCP26Parser2() { + m_chewing_index = bopomofo_index; + m_chewing_index_len = G_N_ELEMENTS(bopomofo_index); + + m_initial_table = chewing_dachen_cp26_initials; + m_middle_table = chewing_dachen_cp26_middles; + m_final_table = chewing_dachen_cp26_finals; + m_tone_table = chewing_dachen_cp26_tones; +} + +bool ChewingDaChenCP26Parser2::in_chewing_scheme(pinyin_option_t options, + const char key, + const char ** symbol) const { + const gchar * chewing = NULL; + unsigned char tone = CHEWING_ZERO_TONE; + + if (search_chewing_symbols(m_initial_table, key, &chewing)) { + if (symbol) + *symbol = chewing; + return true; + } + + if (search_chewing_symbols(m_middle_table, key, &chewing)) { + if (symbol) + *symbol = chewing; + return true; + } + + if (search_chewing_symbols(m_final_table, key, &chewing)) { + if (symbol) + *symbol = chewing; + return true; + } + + if (!(options & USE_TONE)) + return false; + + if (search_chewing_tones(m_tone_table, key, &tone)) { + if (symbol) + *symbol = chewing_tone_table[tone]; + return true; + } + + return false; +} diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h index a58c7b6..948b0a3 100644 --- a/src/storage/pinyin_parser2.h +++ b/src/storage/pinyin_parser2.h @@ -195,6 +195,29 @@ public: bool in_chewing_scheme(pinyin_option_t options, const char key, const char ** symbol) const; }; +class ChewingDaChenCP26Parser2 : public PhoneticParser2 +{ + /* some internal pointers to chewing scheme table. */ + const chewing_index_item_t * m_chewing_index; + size_t m_chewing_index_len; + const chewing_symbol_item_t * m_initial_table; + const chewing_symbol_item_t * m_middle_table; + const chewing_symbol_item_t * m_final_table; + const chewing_tone_item_t * m_tone_table; + +public: + ChewingDaChenCP26Parser2(); + + virtual ~ChewingDaChenCP26Parser2() {} + + virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, const char *str, int len) const; + + virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const; + +public: + bool in_chewing_scheme(pinyin_option_t options, const char key, const char ** symbol) const; +}; + /* compare pinyins with chewing internal representations. */ inline int pinyin_compare_initial2(pinyin_option_t options, ChewingInitial lhs, |