summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-12-14 13:06:11 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-14 13:06:11 +0800
commit2970679b136f91607f7db1d1a64c3158b1d60881 (patch)
tree33ce2f3f32ef8f91eab4d9028845204c9002300c
parent23e34dfe67ef11c44b196337cd42e4f000f9b9fc (diff)
downloadlibpinyin-2970679b136f91607f7db1d1a64c3158b1d60881.tar.gz
libpinyin-2970679b136f91607f7db1d1a64c3158b1d60881.tar.xz
libpinyin-2970679b136f91607f7db1d1a64c3158b1d60881.zip
add get string to chewing key
-rw-r--r--scripts/chewing_enum.h.in9
-rw-r--r--src/storage/chewing_key.h12
-rw-r--r--src/storage/pinyin_parser2.cpp35
3 files changed, 56 insertions, 0 deletions
diff --git a/scripts/chewing_enum.h.in b/scripts/chewing_enum.h.in
new file mode 100644
index 0000000..dc230ae
--- /dev/null
+++ b/scripts/chewing_enum.h.in
@@ -0,0 +1,9 @@
+/* This file is generated by python scripts. Don't edit this file directly.
+ */
+
+#ifndef CHEWING_ENUM_H
+#define CHEWING_ENUM_H
+
+
+
+#endif
diff --git a/src/storage/chewing_key.h b/src/storage/chewing_key.h
index ec8c7a3..9f6526e 100644
--- a/src/storage/chewing_key.h
+++ b/src/storage/chewing_key.h
@@ -174,6 +174,13 @@ struct ChewingKey
m_final = final;
m_tone = CHEWING_ZERO_TONE;
}
+
+public:
+ gint get_table_index();
+
+ /* Note: the return value should be freed by g_free. */
+ gchar * get_pinyin_string();
+ gchar * get_chewing_string();
};
static inline bool operator == (ChewingKey lhs, ChewingKey rhs) {
@@ -190,6 +197,11 @@ static inline bool operator == (ChewingKey lhs, ChewingKey rhs) {
struct ChewingKeyRest
{
+ /* Note: the table index is deprecated,
+ * and will be removed in the next major release.
+ * Currently this is kept for debugging purpose.
+ * Please use get_table_index in ChewingKey.
+ */
guint16 m_table_index; /* the index in pinyin parser table. */
guint16 m_raw_begin; /* the begin of the raw input. */
guint16 m_raw_end; /* the end of the raw input. */
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index 2e2b649..7adf9a7 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -72,6 +72,41 @@ static bool check_chewing_options(pinyin_option_t options, const chewing_index_i
}
+gint ChewingKey::get_table_index() {
+ assert(m_initial < CHEWING_NUMBER_OF_INITIALS);
+ assert(m_middle < CHEWING_NUMBER_OF_MIDDLES);
+ assert(m_final < CHEWING_NUMBER_OF_FINALS);
+
+ gint index = chewing_key_table[(m_initial * CHEWING_NUMBER_OF_MIDDLES + m_middle) * CHEWING_NUMBER_OF_FINALS + m_final];
+ return index == -1 ? 0 : index;
+}
+
+gchar * ChewingKey::get_pinyin_string() {
+ assert(m_tone < CHEWING_NUMBER_OF_TONES);
+ gint index = get_table_index();
+ const content_table_item_t & item = content_table[index];
+
+ if (CHEWING_ZERO_TONE == m_tone) {
+ return g_strdup(item.m_pinyin_str);
+ } else {
+ return g_strdup_printf("%s%d", item.m_pinyin_str, m_tone);
+ }
+}
+
+gchar * ChewingKey::get_chewing_string() {
+ assert(m_tone < CHEWING_NUMBER_OF_TONES);
+ gint index = get_table_index();
+ const content_table_item_t & item = content_table[index];
+
+ if (CHEWING_ZERO_TONE == m_tone) {
+ return g_strdup(item.m_chewing_str);
+ } else {
+ return g_strdup_printf("%s%s", item.m_chewing_str,
+ chewing_tone_table[m_tone]);
+ }
+}
+
+
/* methods for Chewing Keys to access pinyin parser table. */
const char * ChewingKeyRest::get_pinyin_string(){
if (m_table_index == 0)