From f699a47356f3ec5062a505ec2e5cddd929144ce3 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 14 Oct 2015 11:00:57 +0800 Subject: clean pinyin_parser2.cpp --- src/storage/pinyin_parser2.cpp | 183 ----------------------------------------- 1 file changed, 183 deletions(-) (limited to 'src/storage') diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp index df17a11..d3442ee 100644 --- a/src/storage/pinyin_parser2.cpp +++ b/src/storage/pinyin_parser2.cpp @@ -58,20 +58,6 @@ static bool check_pinyin_options(pinyin_option_t options, const pinyin_index_ite return true; } -static bool check_chewing_options(pinyin_option_t options, const chewing_index_item_t * item) { - guint32 flags = item->m_flags; - assert (flags & IS_ZHUYIN); - - /* handle incomplete chewing. */ - if (flags & ZHUYIN_INCOMPLETE) { - if (!(options & ZHUYIN_INCOMPLETE)) - return false; - } - - return true; -} - - gint _ChewingKey::get_table_index() { assert(m_initial < CHEWING_NUMBER_OF_INITIALS); assert(m_middle < CHEWING_NUMBER_OF_MIDDLES); @@ -847,172 +833,3 @@ bool DoublePinyinParser2::set_scheme(DoublePinyinScheme scheme) { return false; /* no such scheme. */ } - -/* the chewing string must be freed with g_free. */ -static bool search_chewing_symbols(const chewing_symbol_item_t * symbol_table, - const char key, const char ** chewing) { - *chewing = NULL; - /* just iterate the table, as we only have < 50 items. */ - while (symbol_table->m_input != '\0') { - if (symbol_table->m_input == key) { - *chewing = symbol_table->m_chewing; - return true; - } - symbol_table ++; - } - return false; -} - -static bool search_chewing_tones(const chewing_tone_item_t * tone_table, - const char key, unsigned char * tone) { - *tone = CHEWING_ZERO_TONE; - /* just iterate the table, as we only have < 10 items. */ - while (tone_table->m_input != '\0') { - if (tone_table->m_input == key) { - *tone = tone_table->m_tone; - return true; - } - tone_table ++; - } - return false; -} - - -bool ChewingParser2::parse_one_key(pinyin_option_t options, - ChewingKey & key, - const char *str, int len) const { - options &= ~(PINYIN_CORRECT_ALL|PINYIN_AMB_ALL); - unsigned char tone = CHEWING_ZERO_TONE; - - int symbols_len = len; - /* probe whether the last key is tone key in str. */ - if (options & USE_TONE) { - char ch = str[len - 1]; - /* remove tone from input */ - if (search_chewing_tones(m_tone_table, ch, &tone)) - symbols_len --; - } - - int i; - gchar * chewing = NULL; const char * onechar = NULL; - - /* probe the possible chewing map in the rest of str. */ - for (i = 0; i < symbols_len; ++i) { - if (!search_chewing_symbols(m_symbol_table, str[i], &onechar)) { - g_free(chewing); - return false; - } - - if (!chewing) { - chewing = g_strdup(onechar); - } else { - gchar * tmp = chewing; - chewing = g_strconcat(chewing, onechar, NULL); - g_free(tmp); - } - } - - /* search the chewing in the chewing index table. */ - if (chewing && search_chewing_index(options, chewing, key)) { - /* save back tone if available. */ - key.m_tone = tone; - g_free(chewing); - return true; - } - - g_free(chewing); - return false; -} - - -/* only characters in chewing keyboard scheme are accepted here. */ -int ChewingParser2::parse(pinyin_option_t options, ChewingKeyVector & keys, - ChewingKeyRestVector & key_rests, - const char *str, int len) const { - g_array_set_size(keys, 0); - g_array_set_size(key_rests, 0); - - int maximum_len = 0; int i; - /* probe the longest possible chewing string. */ - for (i = 0; i < len; ++i) { - if (!in_chewing_scheme(options, str[i], NULL)) - break; - } - maximum_len = i; - - /* maximum forward match for chewing. */ - int parsed_len = 0; - while (parsed_len < maximum_len) { - const char * cur_str = str + parsed_len; - i = std_lite::min(maximum_len - parsed_len, - (int)max_chewing_length); - - ChewingKey key; ChewingKeyRest key_rest; - for (; i > 0; --i) { - bool success = parse_one_key(options, key, cur_str, i); - if (success) - break; - } - - if (0 == i) /* no more possible chewings. */ - break; - - key_rest.m_raw_begin = parsed_len; key_rest.m_raw_end = parsed_len + i; - parsed_len += i; - - /* save the pinyin. */ - g_array_append_val(keys, key); - g_array_append_val(key_rests, key_rest); - } - - return parsed_len; -} - - -bool ChewingParser2::set_scheme(ZhuyinScheme scheme) { - switch(scheme) { - case ZHUYIN_STANDARD: - m_symbol_table = chewing_standard_symbols; - m_tone_table = chewing_standard_tones; - return true; - case ZHUYIN_IBM: - m_symbol_table = chewing_ibm_symbols; - m_tone_table = chewing_ibm_tones; - return true; - case ZHUYIN_GINYIEH: - m_symbol_table = chewing_ginyieh_symbols; - m_tone_table = chewing_ginyieh_tones; - return true; - case ZHUYIN_ETEN: - m_symbol_table = chewing_eten_symbols; - m_tone_table = chewing_eten_tones; - return true; - } - - return false; -} - - -bool ChewingParser2::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_symbol_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; -} -- cgit