summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libzhuyin.ver1
-rw-r--r--src/zhuyin.cpp38
-rw-r--r--src/zhuyin.h16
3 files changed, 53 insertions, 2 deletions
diff --git a/src/libzhuyin.ver b/src/libzhuyin.ver
index 4876bac..c448734 100644
--- a/src/libzhuyin.ver
+++ b/src/libzhuyin.ver
@@ -46,6 +46,7 @@ LIBZHUYIN {
zhuyin_get_zhuyin_key_rest;
zhuyin_get_zhuyin_key_rest_positions;
zhuyin_get_zhuyin_key_rest_length;
+ zhuyin_get_zhuyin_key_rest_offset;
zhuyin_get_raw_full_pinyin;
zhuyin_get_n_phrase;
zhuyin_get_phrase_token;
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;
diff --git a/src/zhuyin.h b/src/zhuyin.h
index 398b8d0..24128eb 100644
--- a/src/zhuyin.h
+++ b/src/zhuyin.h
@@ -619,7 +619,7 @@ bool zhuyin_get_zhuyin_key_rest_positions(zhuyin_instance_t * instance,
* @length: the length of the corresponding pinyin key.
* @returns: whether the get operation is successful.
*
- * Get the length of the corresponding pinyin key.
+ * Get the length of the corresponding zhuyin key.
*
*/
bool zhuyin_get_zhuyin_key_rest_length(zhuyin_instance_t * instance,
@@ -627,6 +627,20 @@ bool zhuyin_get_zhuyin_key_rest_length(zhuyin_instance_t * instance,
guint16 * length);
/**
+ * zhuyin_get_zhuyin_key_rest_offset:
+ * @instance: the zhuyin instance.
+ * @cursor: the cursor.
+ * @offset: the offset in the zhuyin array.
+ * @returns: whether the get operation is successful.
+ *
+ * Get the offset in the zhuyin key array.
+ *
+ */
+bool zhuyin_get_zhuyin_key_rest_offset(zhuyin_instance_t * instance,
+ guint16 cursor,
+ guint16 * offset);
+
+/**
* zhuyin_get_raw_full_pinyin:
* @instance: the zhuyin instance.
* @utf8_str: the modified raw full pinyin after choose candidate.