summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-12-05 11:35:17 +0800
committerPeng Wu <alexepico@gmail.com>2012-12-05 11:43:17 +0800
commit20fde3f877ec9448671c2a97ab035b3d844433c0 (patch)
treee61463f7b8c4c4704cc2f72f6bb7de81c7db799f
parenta981d9a0704b84b04b90dcedfcf96c20c9ed4bb8 (diff)
downloadlibpinyin-20fde3f877ec9448671c2a97ab035b3d844433c0.tar.gz
libpinyin-20fde3f877ec9448671c2a97ab035b3d844433c0.tar.xz
libpinyin-20fde3f877ec9448671c2a97ab035b3d844433c0.zip
fixes pinyin_translate_token
-rw-r--r--src/pinyin.cpp13
-rw-r--r--tests/test_phrase.cpp2
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);
}