diff options
author | Peng Wu <alexepico@gmail.com> | 2014-07-08 13:46:15 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-07-08 16:22:17 +0800 |
commit | cac4f26d0fa03fd133e5d247a9989cd19e847c11 (patch) | |
tree | 2e46d12251153d93d43be86696734632685bda6b /src/zhuyin.cpp | |
parent | a9ef80b97764405047f93c4c4cca75ff898b35b5 (diff) | |
download | libzhuyin-cac4f26d0fa03fd133e5d247a9989cd19e847c11.tar.gz libzhuyin-cac4f26d0fa03fd133e5d247a9989cd19e847c11.tar.xz libzhuyin-cac4f26d0fa03fd133e5d247a9989cd19e847c11.zip |
add function zhuyin_get_zhuyin_key_rest_offset0.9.99.20140718
Diffstat (limited to 'src/zhuyin.cpp')
-rw-r--r-- | src/zhuyin.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/zhuyin.cpp b/src/zhuyin.cpp index 56e8f14..67a7bc2 100644 --- a/src/zhuyin.cpp +++ b/src/zhuyin.cpp @@ -1630,7 +1630,8 @@ bool zhuyin_get_zhuyin_key(zhuyin_instance_t * instance, bool zhuyin_get_zhuyin_key_rest(zhuyin_instance_t * instance, guint index, ChewingKeyRest ** key_rest) { - ChewingKeyRestVector & pinyin_key_rests = instance->m_pinyin_key_rests; + ChewingKeyRestVector & pinyin_key_rests = + instance->m_pinyin_key_rests; *key_rest = NULL; @@ -1661,6 +1662,41 @@ bool zhuyin_get_zhuyin_key_rest_length(zhuyin_instance_t * instance, return true; } +bool zhuyin_get_zhuyin_key_rest_offset(zhuyin_instance_t * instance, + guint16 cursor, + guint16 * offset) { + assert (cursor <= instance->m_parsed_len); + + *offset = 0; + + guint len = 0; + assert (instance->m_pinyin_keys->len == + instance->m_pinyin_key_rests->len); + len = instance->m_pinyin_key_rests->len; + + ChewingKeyRestVector & pinyin_key_rests = + instance->m_pinyin_key_rests; + + guint inner_cursor = len; + + guint16 prev_end = 0, cur_end; + for (size_t i = 0; i < len; ++i) { + ChewingKeyRest *pos = NULL; + pos = &g_array_index(pinyin_key_rests, ChewingKeyRest, i); + cur_end = pos->m_raw_end; + + if (prev_end <= cursor && cursor < cur_end) + inner_cursor = i; + + prev_end = cur_end; + } + + assert (inner_cursor >= 0); + *offset = inner_cursor; + + return true; +} + bool zhuyin_get_raw_full_pinyin(zhuyin_instance_t * instance, const gchar ** utf8_str) { *utf8_str = instance->m_raw_full_pinyin; |