From 7c22b7f13486979c5fc5bb16dc8dbf03f7b5a0d8 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 24 Apr 2012 16:47:35 +0800 Subject: refine _try_resplit_table --- src/pinyin.cpp | 64 +++++++++++++++++++--------------------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/src/pinyin.cpp b/src/pinyin.cpp index c4e477d..02f60cb 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -875,64 +875,42 @@ static bool _try_resplit_table(pinyin_instance_t * instance, /* there are no same couple of pinyins in re-split table. */ assert(!(item_by_orig && item_by_new)); + ChewingKey resplit_keys[2]; + const char * pinyins[2]; + bool tosearch = false; if (item_by_orig && item_by_orig->m_new_freq) { - const char * pinyin = item_by_orig->m_new_keys[0]; + pinyins[0] = item_by_orig->m_new_keys[0]; + pinyins[1] = item_by_orig->m_new_keys[1]; + assert(context->m_full_pinyin_parser-> parse_one_key(options, resplit_keys[0], - pinyin, strlen(pinyin))); - pinyin = item_by_orig->m_new_keys[1]; + pinyins[0], strlen(pinyins[0]))); + assert(context->m_full_pinyin_parser-> parse_one_key(options, resplit_keys[1], - pinyin, strlen(pinyin))); - - gchar * new_pinyins = g_strdup_printf - ("%s'%s", item_by_orig->m_new_keys[0], - item_by_orig->m_new_keys[1]); - - /* propagate the tone */ - if (options & USE_TONE) { - if (CHEWING_ZERO_TONE != next_tone) { - assert(0 < next_tone && next_tone <= 5); - resplit_keys[1].m_tone = next_tone; - - gchar * tmp_str = g_strdup_printf - ("%s%d", new_pinyins, next_tone); - g_free(new_pinyins); - new_pinyins = tmp_str; - } - } - - /* do pinyin search. */ - int retval = context->m_pinyin_table->search - (2, resplit_keys, ranges); - - if (retval & SEARCH_OK) { - lookup_candidate_t template_item; - template_item.m_candidate_type = RESPLIT_CANDIDATE; - template_item.m_orig_rest = orig_rest; - template_item.m_new_pinyins = new_pinyins; - - _append_items(context, ranges, &template_item, items); - found = true; - } - g_free(new_pinyins); + pinyins[1], strlen(pinyins[1]))); + tosearch = true; } if (item_by_new && item_by_new->m_orig_freq) { - const char * pinyin = item_by_new->m_orig_keys[0]; + pinyins[0] = item_by_new->m_orig_keys[0]; + pinyins[1] = item_by_new->m_orig_keys[1]; + assert(context->m_full_pinyin_parser-> parse_one_key(options, resplit_keys[0], - pinyin, strlen(pinyin))); - pinyin = item_by_new->m_orig_keys[1]; + pinyins[0], strlen(pinyins[0]))); + assert(context->m_full_pinyin_parser-> parse_one_key(options, resplit_keys[1], - pinyin, strlen(pinyin))); + pinyins[1], strlen(pinyins[1]))); + tosearch = true; + } + if (tosearch) { gchar * new_pinyins = g_strdup_printf - ("%s'%s", item_by_new->m_orig_keys[0], - item_by_new->m_orig_keys[1]); + ("%s'%s", pinyins[0], pinyins[1]); /* propagate the tone */ if (options & USE_TONE) { @@ -947,7 +925,7 @@ static bool _try_resplit_table(pinyin_instance_t * instance, } } - /* do pinyin search */ + /* do pinyin search. */ int retval = context->m_pinyin_table->search (2, resplit_keys, ranges); -- cgit