summaryrefslogtreecommitdiffstats
path: root/src/storage/pinyin_phrase2.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-01-07 14:28:02 +0800
committerPeng Wu <alexepico@gmail.com>2016-01-07 14:28:02 +0800
commit5bc4719fb6e74db0a0d3296fd7dce021b457352d (patch)
tree1cf6e783d68e09c36034ba41790f8db898383eb1 /src/storage/pinyin_phrase2.h
parenta9c1c8359c45e5186865adf027b18d2facdbd313 (diff)
downloadlibpinyin-5bc4719fb6e74db0a0d3296fd7dce021b457352d.tar.gz
libpinyin-5bc4719fb6e74db0a0d3296fd7dce021b457352d.tar.xz
libpinyin-5bc4719fb6e74db0a0d3296fd7dce021b457352d.zip
refactor code
Diffstat (limited to 'src/storage/pinyin_phrase2.h')
-rw-r--r--src/storage/pinyin_phrase2.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index ba2f32e..e07371f 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -63,6 +63,107 @@ inline int pinyin_exact_compare2(const ChewingKey * key_lhs,
}
+/* compare pinyins with chewing internal representations. */
+inline int pinyin_compare_initial2(pinyin_option_t options,
+ ChewingInitial lhs,
+ ChewingInitial rhs) {
+ if (lhs == rhs)
+ return 0;
+
+ if ((options & PINYIN_AMB_C_CH) &&
+ ((lhs == CHEWING_C && rhs == CHEWING_CH) ||
+ (lhs == CHEWING_CH && rhs == CHEWING_C)))
+ return 0;
+
+ if ((options & PINYIN_AMB_S_SH) &&
+ ((lhs == CHEWING_S && rhs == CHEWING_SH) ||
+ (lhs == CHEWING_SH && rhs == CHEWING_S)))
+ return 0;
+
+ if ((options & PINYIN_AMB_Z_ZH) &&
+ ((lhs == CHEWING_Z && rhs == CHEWING_ZH) ||
+ (lhs == CHEWING_ZH && rhs == CHEWING_Z)))
+ return 0;
+
+ if ((options & PINYIN_AMB_F_H) &&
+ ((lhs == CHEWING_F && rhs == CHEWING_H) ||
+ (lhs == CHEWING_H && rhs == CHEWING_F)))
+ return 0;
+
+ if ((options & PINYIN_AMB_L_N) &&
+ ((lhs == CHEWING_L && rhs == CHEWING_N) ||
+ (lhs == CHEWING_N && rhs == CHEWING_L)))
+ return 0;
+
+ if ((options & PINYIN_AMB_L_R) &&
+ ((lhs == CHEWING_L && rhs == CHEWING_R) ||
+ (lhs == CHEWING_R && rhs == CHEWING_L)))
+ return 0;
+
+ if ((options & PINYIN_AMB_G_K) &&
+ ((lhs == CHEWING_G && rhs == CHEWING_K) ||
+ (lhs == CHEWING_K && rhs == CHEWING_G)))
+ return 0;
+
+ return (lhs - rhs);
+}
+
+
+inline int pinyin_compare_middle_and_final2(pinyin_option_t options,
+ ChewingMiddle middle_lhs,
+ ChewingMiddle middle_rhs,
+ ChewingFinal final_lhs,
+ ChewingFinal final_rhs) {
+ if (middle_lhs == middle_rhs && final_lhs == final_rhs)
+ return 0;
+
+ /* both pinyin and chewing incomplete options will enable this. */
+ if (options & (PINYIN_INCOMPLETE | ZHUYIN_INCOMPLETE)) {
+ if (middle_lhs == CHEWING_ZERO_MIDDLE &&
+ final_lhs == CHEWING_ZERO_FINAL)
+ return 0;
+ if (middle_rhs == CHEWING_ZERO_MIDDLE &&
+ final_rhs == CHEWING_ZERO_FINAL)
+ return 0;
+ }
+
+ /* compare chewing middle first. */
+ int middle_diff = middle_lhs - middle_rhs;
+ if (middle_diff)
+ return middle_diff;
+
+ if ((options & PINYIN_AMB_AN_ANG) &&
+ ((final_lhs == CHEWING_AN && final_rhs == CHEWING_ANG) ||
+ (final_lhs == CHEWING_ANG && final_rhs == CHEWING_AN)))
+ return 0;
+
+ if ((options & PINYIN_AMB_EN_ENG) &&
+ ((final_lhs == CHEWING_EN && final_rhs == CHEWING_ENG) ||
+ (final_lhs == CHEWING_ENG && final_rhs == CHEWING_EN)))
+ return 0;
+
+ if ((options & PINYIN_AMB_IN_ING) &&
+ ((final_lhs == PINYIN_IN && final_rhs == PINYIN_ING) ||
+ (final_lhs == PINYIN_ING && final_rhs == PINYIN_IN)))
+ return 0;
+
+ return (final_lhs - final_rhs);
+}
+
+
+inline int pinyin_compare_tone2(pinyin_option_t options,
+ ChewingTone lhs,
+ ChewingTone rhs) {
+ if (lhs == rhs)
+ return 0;
+ if (lhs == CHEWING_ZERO_TONE)
+ return 0;
+ if (rhs == CHEWING_ZERO_TONE)
+ return 0;
+ return (lhs - rhs);
+}
+
+
inline int pinyin_compare_with_ambiguities2(pinyin_option_t options,
const ChewingKey * key_lhs,
const ChewingKey * key_rhs,