summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-29 13:56:11 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-29 13:56:11 +0800
commit9c9a11038a30285b3537af3f0df2d3331acd7ec0 (patch)
tree7cdc81d5e154a5e123a20ab0df4955aa63379c57
parent4e9139c635feb783ca5702394d331e4559318eba (diff)
downloadlibpinyin-9c9a11038a30285b3537af3f0df2d3331acd7ec0.tar.gz
libpinyin-9c9a11038a30285b3537af3f0df2d3331acd7ec0.tar.xz
libpinyin-9c9a11038a30285b3537af3f0df2d3331acd7ec0.zip
add type pinyin_option_t
-rw-r--r--src/include/novel_types.h2
-rw-r--r--src/storage/pinyin_parser2.cpp24
-rw-r--r--src/storage/pinyin_parser2.h25
-rw-r--r--src/storage/pinyin_phrase2.h6
4 files changed, 30 insertions, 27 deletions
diff --git a/src/include/novel_types.h b/src/include/novel_types.h
index 110d041..07fe699 100644
--- a/src/include/novel_types.h
+++ b/src/include/novel_types.h
@@ -153,6 +153,8 @@ typedef TokenVector MatchResults;
/* Array of lookup_constraint_t */
typedef GArray * CandidateConstraints;
+typedef guint32 pinyin_option_t;
+
};
#endif
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index 1b6af3c..568380c 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -20,11 +20,11 @@
*/
+#include "pinyin_parser2.h"
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "stl_lite.h"
-#include "pinyin_parser2.h"
#include "pinyin_phrase2.h"
#include "pinyin_custom2.h"
#include "chewing_key.h"
@@ -35,7 +35,7 @@
using namespace pinyin;
-static bool check_pinyin_options(guint32 options, const pinyin_index_item_t * item) {
+static bool check_pinyin_options(pinyin_option_t options, const pinyin_index_item_t * item) {
guint32 flags = item->m_flags;
assert (flags & IS_PINYIN);
@@ -57,7 +57,7 @@ static bool check_pinyin_options(guint32 options, const pinyin_index_item_t * it
return true;
}
-static bool check_chewing_options(guint32 options, const chewing_index_item_t * item) {
+static bool check_chewing_options(pinyin_option_t options, const chewing_index_item_t * item) {
guint32 flags = item->m_flags;
assert (flags & IS_CHEWING);
@@ -121,7 +121,7 @@ static bool compare_pinyin_less_than(const pinyin_index_item_t & lhs,
return 0 > strcmp(lhs.m_pinyin_input, rhs.m_pinyin_input);
}
-static inline bool search_pinyin_index(guint32 options, const char * pinyin,
+static inline bool search_pinyin_index(pinyin_option_t options, const char * pinyin,
ChewingKey & key,
ChewingKeyRest & key_rest){
pinyin_index_item_t item;
@@ -155,7 +155,7 @@ static bool compare_chewing_less_than(const chewing_index_item_t & lhs,
return 0 > strcmp(lhs.m_chewing_input, rhs.m_chewing_input);
}
-static inline bool search_chewing_index(guint32 options, const char * chewing,
+static inline bool search_chewing_index(pinyin_option_t options, const char * chewing,
ChewingKey & key,
ChewingKeyRest & key_rest){
chewing_index_item_t item;
@@ -191,7 +191,7 @@ FullPinyinParser2::FullPinyinParser2 (){
}
-bool FullPinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
+bool FullPinyinParser2::parse_one_key (pinyin_option_t options, ChewingKey & key,
ChewingKeyRest & key_rest,
const char * pinyin, int len) const {
/* "'" are not accepted in parse_one_key. */
@@ -235,7 +235,7 @@ bool FullPinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
}
-int FullPinyinParser2::parse (guint32 options, ChewingKeyVector & keys,
+int FullPinyinParser2::parse (pinyin_option_t options, ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests,
const char *str, int len) const {
int i;
@@ -366,7 +366,7 @@ int FullPinyinParser2::final_step(size_t step_len, ChewingKeyVector & keys,
}
-bool FullPinyinParser2::post_process(guint32 options,
+bool FullPinyinParser2::post_process(pinyin_option_t options,
ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests) const {
int i;
@@ -433,7 +433,7 @@ bool FullPinyinParser2::post_process(guint32 options,
#define IS_KEY(x) (('a' <= x && x <= 'z') || x == ';')
-bool DoublePinyinParser2::parse_one_key(guint32 options, ChewingKey & key,
+bool DoublePinyinParser2::parse_one_key(pinyin_option_t options, ChewingKey & key,
ChewingKeyRest & key_rest,
const char *str, int len) const {
@@ -519,7 +519,7 @@ bool DoublePinyinParser2::parse_one_key(guint32 options, ChewingKey & key,
/* only 'a'-'z' and ';' are accepted here. */
-int DoublePinyinParser2::parse(guint32 options, ChewingKeyVector & keys,
+int DoublePinyinParser2::parse(pinyin_option_t options, ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests,
const char *str, int len) const {
g_array_set_size(keys, 0);
@@ -627,7 +627,7 @@ static bool search_chewing_tones(const chewing_tone_item_t * tone_table,
}
-bool ChewingParser2::parse_one_key(guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const {
+bool ChewingParser2::parse_one_key(pinyin_option_t options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const {
char tone = CHEWING_ZERO_TONE;
int symbols_len = len;
@@ -675,7 +675,7 @@ bool ChewingParser2::parse_one_key(guint32 options, ChewingKey & key, ChewingKey
/* only characters in chewing keyboard scheme are accepted here. */
-int ChewingParser2::parse(guint32 options, ChewingKeyVector & keys,
+int ChewingParser2::parse(pinyin_option_t options, ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests,
const char *str, int len) const {
g_array_set_size(keys, 0);
diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h
index e6c27f2..04bbffc 100644
--- a/src/storage/pinyin_parser2.h
+++ b/src/storage/pinyin_parser2.h
@@ -23,6 +23,7 @@
#define PINYIN_PARSER2_H
#include <glib.h>
+#include "novel_types.h"
#include "chewing_key.h"
#include "pinyin_custom2.h"
@@ -104,7 +105,7 @@ public:
*
* @return whether the entire string is parsed as one key.
*/
- virtual bool parse_one_key(guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const = 0;
+ virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const = 0;
/**
* @brief Translate the source string into a set of ChewingKeys.
@@ -119,7 +120,7 @@ public:
/* Note:
* the parse method will use dynamic programming to drive parse_one_key.
*/
- virtual int parse(guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const = 0;
+ virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const = 0;
};
@@ -137,7 +138,7 @@ protected:
int final_step(size_t step_len, ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests) const;
- bool post_process(guint32 options, ChewingKeyVector & keys,
+ bool post_process(pinyin_option_t options, ChewingKeyVector & keys,
ChewingKeyRestVector & key_rests) const;
public:
@@ -146,9 +147,9 @@ public:
g_array_free(m_parse_steps, TRUE);
}
- virtual bool parse_one_key(guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
- virtual int parse(guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
+ virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
};
@@ -169,9 +170,9 @@ public:
virtual ~DoublePinyinParser2() {}
- virtual bool parse_one_key(guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
- virtual int parse(guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
+ virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
public:
bool set_scheme(DoublePinyinScheme scheme);
@@ -206,9 +207,9 @@ public:
virtual ~ChewingParser2() {}
- virtual bool parse_one_key(guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key(pinyin_option_t options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
- virtual int parse(guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
+ virtual int parse(pinyin_option_t options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
public:
bool set_scheme(ChewingScheme scheme);
@@ -217,7 +218,7 @@ public:
/* compare pinyins with chewing internal representations. */
-inline int pinyin_compare_initial2(guint32 options,
+inline int pinyin_compare_initial2(pinyin_option_t options,
ChewingInitial lhs,
ChewingInitial rhs) {
if (lhs == rhs)
@@ -262,7 +263,7 @@ inline int pinyin_compare_initial2(guint32 options,
}
-inline int pinyin_compare_middle_and_final2(guint32 options,
+inline int pinyin_compare_middle_and_final2(pinyin_option_t options,
ChewingMiddle middle_lhs,
ChewingMiddle middle_rhs,
ChewingFinal final_lhs,
@@ -304,7 +305,7 @@ inline int pinyin_compare_middle_and_final2(guint32 options,
}
-inline int pinyin_compare_tone2(guint32 options,
+inline int pinyin_compare_tone2(pinyin_option_t options,
ChewingTone lhs,
ChewingTone rhs) {
if (lhs == rhs)
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index d927ed9..074f545 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -63,7 +63,7 @@ inline int pinyin_exact_compare2(const ChewingKey * key_lhs,
}
-inline int pinyin_compare_with_ambiguities2(guint32 options,
+inline int pinyin_compare_with_ambiguities2(pinyin_option_t options,
const ChewingKey * key_lhs,
const ChewingKey * key_rhs,
int phrase_length){
@@ -106,7 +106,7 @@ inline int pinyin_compare_with_ambiguities2(guint32 options,
}
/* compute pinyin lower bound */
-inline void compute_lower_value2(guint32 options,
+inline void compute_lower_value2(pinyin_option_t options,
ChewingKey * in_keys,
ChewingKey * out_keys,
int phrase_length) {
@@ -162,7 +162,7 @@ inline void compute_lower_value2(guint32 options,
}
/* compute pinyin upper bound */
-inline void compute_upper_value2(guint32 options,
+inline void compute_upper_value2(pinyin_option_t options,
ChewingKey * in_keys,
ChewingKey * out_keys,
int phrase_length) {