From c253c4fcbf2a9b49224a825f5e5dcffcb412d0a0 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 8 Jan 2016 12:30:15 +0800 Subject: refactor code --- src/storage/pinyin_phrase2.h | 34 ----------------------- src/storage/pinyin_phrase3.h | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 34 deletions(-) create mode 100644 src/storage/pinyin_phrase3.h (limited to 'src') diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h index e07371f..fab19c7 100644 --- a/src/storage/pinyin_phrase2.h +++ b/src/storage/pinyin_phrase2.h @@ -29,40 +29,6 @@ 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; -} - - /* compare pinyins with chewing internal representations. */ inline int pinyin_compare_initial2(pinyin_option_t options, ChewingInitial lhs, diff --git a/src/storage/pinyin_phrase3.h b/src/storage/pinyin_phrase3.h new file mode 100644 index 0000000..b99bc15 --- /dev/null +++ b/src/storage/pinyin_phrase3.h @@ -0,0 +1,66 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2016 Peng Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PINYIN_PHRASE3_H +#define PINYIN_PHRASE3_H + +#include "novel_types.h" +#include "chewing_key.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; +} + + +}; + +#endif -- cgit