From 20fde3f877ec9448671c2a97ab035b3d844433c0 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 5 Dec 2012 11:35:17 +0800 Subject: fixes pinyin_translate_token --- src/pinyin.cpp | 13 ++++++++----- tests/test_phrase.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pinyin.cpp b/src/pinyin.cpp index dff7381..ca1b109 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -1052,8 +1052,9 @@ static bool _compute_phrase_strings_of_items(pinyin_instance_t * instance, case NORMAL_CANDIDATE: case DIVIDED_CANDIDATE: case RESPLIT_CANDIDATE: - pinyin_translate_token - (instance, candidate->m_token, &(candidate->m_phrase_string)); + pinyin_token_get_phrase + (instance, candidate->m_token, NULL, + &(candidate->m_phrase_string)); break; case ZOMBIE_CANDIDATE: break; @@ -1762,7 +1763,6 @@ bool pinyin_token_get_phrase(pinyin_instance_t * instance, phrase_token_t token, guint * len, gchar ** utf8_str) { - *len = 0; *utf8_str = NULL; pinyin_context_t * & context = instance->m_context; PhraseItem item; ucs4_t buffer[MAX_PHRASE_LENGTH]; @@ -1772,8 +1772,11 @@ bool pinyin_token_get_phrase(pinyin_instance_t * instance, return false; item.get_phrase_string(buffer); - *len = item.get_phrase_length(); - *utf8_str = g_ucs4_to_utf8(buffer, *len, NULL, NULL, NULL); + guint length = item.get_phrase_length(); + if (len) + *len = length; + if (utf8_str) + *utf8_str = g_ucs4_to_utf8(buffer, length, NULL, NULL, NULL); return true; } diff --git a/tests/test_phrase.cpp b/tests/test_phrase.cpp index 36603e7..fdee52e 100644 --- a/tests/test_phrase.cpp +++ b/tests/test_phrase.cpp @@ -52,7 +52,7 @@ int main(int argc, char * argv[]){ continue; char * word = NULL; - pinyin_translate_token(instance, token, &word); + pinyin_token_get_phrase(instance, token, NULL, &word); printf("%s\t", word); g_free(word); } -- cgit