summaryrefslogtreecommitdiffstats
path: root/src/storage/pinyin_phrase2.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-17 15:32:52 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-17 15:33:28 +0800
commit96b2e5ba48baa9ada8e64eba9ad43001a90524ce (patch)
tree9d5b20b0475a78cc142e14faa9d1075ff9470a9f /src/storage/pinyin_phrase2.h
parenta9864c66724dc3a74324afc2a28ca801c6ca7477 (diff)
downloadlibpinyin-96b2e5ba48baa9ada8e64eba9ad43001a90524ce.tar.gz
libpinyin-96b2e5ba48baa9ada8e64eba9ad43001a90524ce.tar.xz
libpinyin-96b2e5ba48baa9ada8e64eba9ad43001a90524ce.zip
add pinyin compare 2
Diffstat (limited to 'src/storage/pinyin_phrase2.h')
-rw-r--r--src/storage/pinyin_phrase2.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index 49a2fa8..0f96856 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -19,3 +19,90 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#ifndef PINYIN_PARSER2_H
+#define PINYIN_PARSER2_H
+
+#include "chewing_key.h"
+#include "pinyin_parser2.h"
+
+namespace pinyin{
+
+inline int pinyin_exact_compare2(const ChewingKey * key_lhs,
+ const ChewingKey * key_rhs,
+ int phrase_length){
+ int i;
+ int result;
+
+ /* compare initial */
+ for (i = 0; i < phrase_length; ++i) {
+ result = key_lhs[i].m_initial - key_rhs[i].m_initial;
+ if (0 != result)
+ return result;
+ }
+
+ /* compare middle and final */
+ for (i = 0; i < phrase_length; ++i) {
+ result = key_lhs[i].m_middle - key_rhs[i].m_middle;
+ if (0 != result)
+ return result;
+ result = key_lhs[i].m_final - key_rhs[i].m_final;
+ if (0 != result)
+ return result;
+ }
+
+ /* compare tone */
+ for (i = 0; i < phrase_length; ++i) {
+ result = key_lhs[i].m_tone - key_rhs[i].m_tone;
+ if (0 != result)
+ return result;
+ }
+
+ return 0;
+}
+
+
+inline int pinyin_compare_with_ambiguities2(guint32 options,
+ const ChewingKey * key_lhs,
+ const ChewingKey * key_rhs,
+ int phrase_length){
+ int i;
+ int result;
+
+ /* compare initial */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_initial2
+ (options,
+ (ChewingInitial)key_lhs[i].m_initial,
+ (ChewingInitial)key_rhs[i].m_initial);
+ if (0 != result)
+ return result;
+ }
+
+ /* compare middle and final */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_middle_and_final2
+ (options,
+ (ChewingMiddle)key_lhs[i].m_middle,
+ (ChewingMiddle)key_rhs[i].m_middle,
+ (ChewingFinal) key_lhs[i].m_final,
+ (ChewingFinal) key_rhs[i].m_final);
+ if (0 != result)
+ return result;
+ }
+
+ /* compare tone */
+ for (i = 0; i < phrase_length; ++i) {
+ result = pinyin_compare_tone2
+ (options,
+ (ChewingTone)key_lhs[i].m_tone,
+ (ChewingTone)key_rhs[i].m_tone);
+ if (0 != result)
+ return result;
+ }
+
+ return 0;
+}
+
+};
+
+#endif