summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-10-14 11:26:51 +0800
committerPeng Wu <alexepico@gmail.com>2015-10-14 11:26:51 +0800
commit05288c898565689d191780e3c76f2e665c624280 (patch)
tree7e1a5cae8f8d92057e88a94437f9a6fa596811fb
parent3c89c1aa4c818205cf2e871b932b1f4f0fe3fb21 (diff)
downloadlibpinyin-05288c898565689d191780e3c76f2e665c624280.tar.gz
libpinyin-05288c898565689d191780e3c76f2e665c624280.tar.xz
libpinyin-05288c898565689d191780e3c76f2e665c624280.zip
update pinyin_parser2.cpp
-rw-r--r--src/storage/pinyin_parser2.cpp48
-rw-r--r--src/storage/pinyin_parser2.h8
2 files changed, 29 insertions, 27 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index a5c3985..0015ccc 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -168,31 +168,27 @@ static inline bool search_pinyin_index(pinyin_option_t options,
return false;
}
-static bool compare_chewing_less_than(const chewing_index_item_t & lhs,
- const chewing_index_item_t & rhs){
- return 0 > strcmp(lhs.m_chewing_input, rhs.m_chewing_input);
-}
-
-static inline bool search_chewing_index(pinyin_option_t options,
- const char * chewing,
+static inline bool search_pinyin_index2(pinyin_option_t options,
+ const pinyin_index_item_t * index,
+ size_t len,
+ const char * pinyin,
ChewingKey & key){
- chewing_index_item_t item;
+ pinyin_index_item_t item;
memset(&item, 0, sizeof(item));
- item.m_chewing_input = chewing;
+ item.m_pinyin_input = pinyin;
- std_lite::pair<const chewing_index_item_t *,
- const chewing_index_item_t *> range;
+ std_lite::pair<const pinyin_index_item_t *,
+ const pinyin_index_item_t *> range;
range = std_lite::equal_range
- (zhuyin_index, zhuyin_index + G_N_ELEMENTS(zhuyin_index),
- item, compare_chewing_less_than);
+ (index, index + len,
+ item, compare_pinyin_less_than);
guint16 range_len = range.second - range.first;
- assert (range_len <= 1);
-
+ assert(range_len <= 1);
if (range_len == 1) {
- const chewing_index_item_t * index = range.first;
+ const pinyin_index_item_t * index = range.first;
- if (!check_chewing_options(options, index))
+ if (!check_pinyin_options(options, index))
return false;
key = content_table[index->m_table_index].m_chewing_key;
@@ -203,11 +199,14 @@ static inline bool search_chewing_index(pinyin_option_t options,
return false;
}
+
/* Full Pinyin Parser */
FullPinyinParser2::FullPinyinParser2 (){
+ m_pinyin_index = NULL; m_pinyin_index_len = 0;
m_parse_steps = g_array_new(TRUE, FALSE, sizeof(parse_value_t));
-}
+ set_scheme(FULL_PINYIN_DEFAULT);
+}
bool FullPinyinParser2::parse_one_key (pinyin_option_t options,
ChewingKey & key,
@@ -240,7 +239,8 @@ bool FullPinyinParser2::parse_one_key (pinyin_option_t options,
/* Note: optimize here? */
input[parsed_len] = '\0';
- if (!search_pinyin_index(options, input, key)) {
+ if (!search_pinyin_index2(options, m_pinyin_index, m_pinyin_index_len,
+ input, key)) {
g_free(input);
return false;
}
@@ -438,19 +438,19 @@ int FullPinyinParser2::final_step(size_t step_len, ChewingKeyVector & keys,
return parsed_len;
}
-bool FullPinyinParser2::set_scheme(ZhuyinScheme scheme){
+bool FullPinyinParser2::set_scheme(FullPinyinScheme scheme){
switch(scheme){
case FULL_PINYIN_HANYU:
- m_pinyin_index = hanyu_pinyin_index;
- m_pinyin_index_len = G_N_ELEMENTS(hanyu_pinyin_index);
+ m_pinyin_index = pinyin_index;
+ m_pinyin_index_len = G_N_ELEMENTS(pinyin_index);
break;
case FULL_PINYIN_LUOMA:
m_pinyin_index = luoma_pinyin_index;
m_pinyin_index_len = G_N_ELEMENTS(luoma_pinyin_index);
break;
case FULL_PINYIN_SECONDARY_BOPOMOFO:
- m_pinyin_index = secondary_bopomofo_index;
- m_pinyin_index_len = G_N_ELEMENTS(secondary_bopomofo_index);
+ m_pinyin_index = secondary_zhuyin_index;
+ m_pinyin_index_len = G_N_ELEMENTS(secondary_zhuyin_index);
break;
default:
assert(false);
diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h
index 40d96bb..943be20 100644
--- a/src/storage/pinyin_parser2.h
+++ b/src/storage/pinyin_parser2.h
@@ -147,6 +147,8 @@ public:
class FullPinyinParser2 : public PhoneticParser2
{
/* Note: some internal pointers to full pinyin table. */
+ const pinyin_index_item_t * m_pinyin_index;
+ size_t m_pinyin_index_len;
protected:
ParseValueVector m_parse_steps;
@@ -188,7 +190,7 @@ public:
virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
public:
- bool set_scheme(ZhuyinScheme scheme);
+ bool set_scheme(FullPinyinScheme scheme);
};
@@ -280,7 +282,7 @@ protected:
public:
ChewingSimpleParser2() {
m_symbol_table = NULL; m_tone_table = NULL;
- set_scheme(CHEWING_DEFAULT);
+ set_scheme(ZHUYIN_DEFAULT);
}
virtual ~ChewingSimpleParser2() {}
@@ -324,7 +326,7 @@ public:
m_chewing_index = NULL; m_chewing_index_len = 0;
m_initial_table = NULL; m_middle_table = NULL;
m_final_table = NULL; m_tone_table = NULL;
- set_scheme(CHEWING_HSU);
+ set_scheme(ZHUYIN_HSU);
}
virtual ~ChewingDiscreteParser2() {}