summaryrefslogtreecommitdiffstats
path: root/src/zhuyin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zhuyin.cpp')
-rw-r--r--src/zhuyin.cpp38
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;