summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-17 14:11:10 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-17 14:15:50 +0800
commit7fddc0894cf2ea1bff0e10285cf5181d8f076074 (patch)
tree39d5e996ba3850d5227399127f535fa880fe48b8
parent8ec1d25f1e9cf032897e877b084220f0db60d452 (diff)
downloadlibpinyin-7fddc0894cf2ea1bff0e10285cf5181d8f076074.tar.gz
libpinyin-7fddc0894cf2ea1bff0e10285cf5181d8f076074.tar.xz
libpinyin-7fddc0894cf2ea1bff0e10285cf5181d8f076074.zip
write pinyin_compare_middle_and_final2
-rw-r--r--src/storage/pinyin_parser2.h48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h
index c074122..c517f7b 100644
--- a/src/storage/pinyin_parser2.h
+++ b/src/storage/pinyin_parser2.h
@@ -230,16 +230,48 @@ int pinyin_compare_initial2 (guint32 options,
return (lhs - rhs);
}
-int pinyin_compare_middle2 (guint32 options,
- ChewingMiddle lhs,
- ChewingMiddle rhs){
- /* as no fuzzy pinyin option in chewing middle. */
- return (lhs - rhs);
+
+int pinyin_compare_middle_and_final2 (guint32 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 | CHEWING_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);
}
-int pinyin_compare_final2 (guint32 options,
- ChewingFinal lhs,
- ChewingFinal rhs);
int pinyin_compare_tone2 (guint32 options,
ChewingTone lhs,