diff options
author | Hiroshi Sumita <hsumita@google.com> | 2012-01-12 12:45:43 +0900 |
---|---|---|
committer | Hiroshi Sumita <hsumita@google.com> | 2012-01-12 12:45:43 +0900 |
commit | ea35e7571dea7d7f13ad9007ba06a1a53aedeca3 (patch) | |
tree | f652e109c0be978388d109b0a5206acf5da55e02 | |
parent | 98b613a1f019ee44f403f1804e0eda9c941e5bff (diff) | |
download | pyzy-ea35e7571dea7d7f13ad9007ba06a1a53aedeca3.tar.gz |
Check a input character on insert().
BUG=None
TEST=Manual
Review URL: http://codereview.appspot.com/5528073
-rw-r--r-- | src/PyZyDoublePinyinContext.cc | 14 | ||||
-rw-r--r-- | src/PyZyFullPinyinContext.cc | 7 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/PyZyDoublePinyinContext.cc b/src/PyZyDoublePinyinContext.cc index a376622..63d76fe 100644 --- a/src/PyZyDoublePinyinContext.cc +++ b/src/PyZyDoublePinyinContext.cc @@ -56,14 +56,10 @@ DoublePinyinContext::~DoublePinyinContext () bool DoublePinyinContext::insert (char ch) { - int id; - /* is full */ - if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) - return true; + const int id = ID (ch); - id = ID (ch); if (id == -1) { - /* it is not availidate ch */ + /* it is not available ch */ return false; } @@ -72,6 +68,10 @@ DoublePinyinContext::insert (char ch) return false; } + /* is full */ + if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) + return true; + m_text.insert (m_cursor++, ch); if (m_cursor > m_pinyin_len + 2 || updatePinyin (false) == false) { @@ -447,5 +447,3 @@ DoublePinyinContext::updatePinyin (bool all) } }; // namespace PyZy - - diff --git a/src/PyZyFullPinyinContext.cc b/src/PyZyFullPinyinContext.cc index 0e8f4d3..3636f4c 100644 --- a/src/PyZyFullPinyinContext.cc +++ b/src/PyZyFullPinyinContext.cc @@ -19,10 +19,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ +#include <cctype> #include "PyZyFullPinyinContext.h" #include "PyZyConfig.h" #include "PyZyPinyinParser.h" + namespace PyZy { FullPinyinContext::FullPinyinContext (Config & config, PhoneticContext::Observer *observer) @@ -37,6 +39,11 @@ FullPinyinContext::~FullPinyinContext (void) bool FullPinyinContext::insert (char ch) { + if (!islower(ch) && ch != '\'') { + /* it is not available ch */ + return false; + } + /* is full */ if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) return true; |