diff options
author | Peng Wu <alexepico@gmail.com> | 2012-10-18 17:57:39 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-10-18 17:57:39 +0800 |
commit | e16062739449853c9b40c60b807d97fdfc8156bb (patch) | |
tree | fe3fad6575508af36a167a7ee22303824028075e /src/lookup/lookup.cpp | |
parent | a949650e53700d1215bfe91b3f3172bb59fd2901 (diff) | |
download | libpinyin-e16062739449853c9b40c60b807d97fdfc8156bb.tar.gz libpinyin-e16062739449853c9b40c60b807d97fdfc8156bb.tar.xz libpinyin-e16062739449853c9b40c60b807d97fdfc8156bb.zip |
update ngseg
Diffstat (limited to 'src/lookup/lookup.cpp')
-rw-r--r-- | src/lookup/lookup.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/lookup/lookup.cpp b/src/lookup/lookup.cpp index 9370d5f..c32a0ec 100644 --- a/src/lookup/lookup.cpp +++ b/src/lookup/lookup.cpp @@ -28,6 +28,7 @@ namespace pinyin{ bool convert_to_utf8(FacadePhraseIndex * phrase_index, MatchResults match_results, /* in */ const char * delimiter, + /* in */ bool show_tokens, /* out */ char * & result_string){ //init variables if ( NULL == delimiter ) @@ -37,23 +38,34 @@ bool convert_to_utf8(FacadePhraseIndex * phrase_index, PhraseItem item; for ( size_t i = 0; i < match_results->len; ++i ){ - phrase_token_t * token = &g_array_index + phrase_token_t token = g_array_index (match_results, phrase_token_t, i); - if ( null_token == *token ) + if ( null_token == token ) continue; - phrase_index->get_phrase_item(*token, item); + phrase_index->get_phrase_item(token, item); ucs4_t buffer[MAX_PHRASE_LENGTH]; item.get_phrase_string(buffer); guint8 length = item.get_phrase_length(); - gchar * phrase = g_ucs4_to_utf8(buffer, length, NULL, NULL, NULL); - char * tmp = result_string; + gchar * phrase = NULL; + char * tmp = NULL; + + if (show_tokens) { + tmp = g_ucs4_to_utf8(buffer, length, NULL, NULL, NULL); + phrase = g_strdup_printf("%d %s", token, tmp); + g_free(tmp); + } else { + phrase = g_ucs4_to_utf8(buffer, length, NULL, NULL, NULL); + } + + tmp = result_string; if ( NULL == result_string ) result_string = g_strdup(phrase); else result_string = g_strconcat(result_string, delimiter, phrase, NULL); - g_free(tmp); g_free(phrase); + g_free(phrase); + g_free(tmp); } return true; } |