summaryrefslogtreecommitdiffstats
path: root/src/pinyin.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-06-28 10:58:13 +0800
committerPeng Wu <alexepico@gmail.com>2016-06-28 10:58:13 +0800
commitb348cbc5a0cc19ac4f601e9d73b6851768331e5d (patch)
treea7b5cbbabb5468ec5d4a36b83b767501535a5952 /src/pinyin.cpp
parenteedae34d203bc1a07a1d09f7876661649538462a (diff)
downloadlibpinyin-b348cbc5a0cc19ac4f601e9d73b6851768331e5d.tar.gz
libpinyin-b348cbc5a0cc19ac4f601e9d73b6851768331e5d.tar.xz
libpinyin-b348cbc5a0cc19ac4f601e9d73b6851768331e5d.zip
fixes pinyin_get_character_offset function
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r--src/pinyin.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 25da763..ca3fa78 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2815,20 +2815,28 @@ bool pinyin_get_right_character_offset(pinyin_instance_t * instance,
}
bool pinyin_get_character_offset(pinyin_instance_t * instance,
- size_t offset,
- size_t * plength) {
+ size_t cursor,
+ size_t * poffset) {
+ pinyin_context_t * context = instance->m_context;
+ FacadePhraseIndex * phrase_index = context->m_phrase_index;
+
PhoneticKeyMatrix & matrix = instance->m_matrix;
MatchResults results = instance->m_match_results;
- _check_offset(matrix, offset);
- size_t length = 0;
- for (size_t i = 0; i < offset; ++i) {
+ size_t offset = 0;
+ PhraseItem item;
+ for (size_t i = 0; i < cursor; ++i) {
phrase_token_t token = g_array_index(results, phrase_token_t, i);
- if (null_token != token)
- ++length;
+ if (null_token == token)
+ continue;
+
+ int retval = phrase_index->get_phrase_item(token, item);
+ assert(ERROR_OK == retval);
+ guint8 len = item.get_phrase_length();
+ offset += len;
}
- *plength = length;
+ *poffset = offset;
return true;
}