summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-06-23 15:08:12 +0800
committerPeng Wu <alexepico@gmail.com>2016-06-23 15:08:12 +0800
commit3f4ee7e103cf12ed2aae4c088d0449c4a042b688 (patch)
tree58cd0be18e96ebadb8622ba7ed150ba01db66c79
parent6e86a814556844ab5a29f9881ef7a84fdd9cd443 (diff)
downloadlibpinyin-3f4ee7e103cf12ed2aae4c088d0449c4a042b688.tar.gz
libpinyin-3f4ee7e103cf12ed2aae4c088d0449c4a042b688.tar.xz
libpinyin-3f4ee7e103cf12ed2aae4c088d0449c4a042b688.zip
write pinyin_get_character_offset function
-rw-r--r--src/pinyin.cpp17
-rw-r--r--src/pinyin.h14
2 files changed, 31 insertions, 0 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 47e0320..e3f1581 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2814,6 +2814,23 @@ bool pinyin_get_right_character_offset(pinyin_instance_t * instance,
return true;
}
+bool pinyin_get_character_offset(pinyin_instance_t * instance,
+ size_t offset,
+ size_t * plength) {
+ 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) {
+ phrase_token_t token = g_array_index(results, phrase_token_t, i);
+ if (null_token != token)
+ ++length;
+ }
+
+ *plength = length;
+ return true;
+}
#if 0
bool pinyin_get_raw_full_pinyin(pinyin_instance_t * instance,
diff --git a/src/pinyin.h b/src/pinyin.h
index b15925a..de1be7c 100644
--- a/src/pinyin.h
+++ b/src/pinyin.h
@@ -898,6 +898,20 @@ bool pinyin_get_right_character_offset(pinyin_instance_t * instance,
size_t offset,
size_t * right);
+/**
+ * pinyin_get_character_offset:
+ * @instance: the pinyin instance.
+ * @offset: the lookup offset.
+ * @length: the character offset.
+ * @returns: whether the get operation is successful.
+ *
+ * Get the character offset from the lookup offset.
+ *
+ */
+bool pinyin_get_character_offset(pinyin_instance_t * instance,
+ size_t offset,
+ size_t * length);
+
#if 0
/**
* pinyin_get_raw_full_pinyin: