return 0 > strcmp(lhs.m_pinyin_input, rhs.m_pinyin_input);
}
-int FullPinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
- ChewingKeyRest & key_rest,
- const char * pinyin, int len) const {
+bool FullPinyinParser2::parse_one_key (guint32 options, ChewingKey & key,
+ ChewingKeyRest & key_rest,
+ const char * pinyin, int len) const {
/* "'" are not accepted in parse_one_key. */
assert(NULL == strchr(pinyin, '\''));
gchar * input = g_strndup(pinyin, len);
pinyin_index_item_t item;
memset(&item, 0, sizeof(item));
- for (; parsed_len > 0; --parsed_len) {
+ /* Note: optimize here? */
+ for (; parsed_len >= len - 1; --parsed_len) {
input[parsed_len] = '\0';
item.m_pinyin_input = input;
std_lite::pair<const pinyin_index_item_t *,
(pinyin_index, pinyin_index + G_N_ELEMENTS(pinyin_index),
item, compare_less_than);
- guint16 len = range.second - range.first;
- assert (len <= 1);
- if ( len == 1 ) {
+ guint16 range_len = range.second - range.first;
+ assert (range_len <= 1);
+ if ( range_len == 1 ) {
const pinyin_index_item_t * index = range.first;
if (!check_pinyin_options(options, index))
key_rest.m_raw_begin = 0; key_rest.m_raw_end = parsed_len;
g_free(input);
- return parsed_len;
+ return parsed_len == len;
}
* @param str snput string in UTF-8 encoding, in most case this string is just a plain ASCII string.
* @param len the length of str, in number of chars rather than bytes.
*
- * @return the number of chars were actually used.
+ * @return whether the entire string is parsed as one key.
*/
- virtual int parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const = 0;
+ virtual bool parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const = 0;
/**
* @brief Translate the source string into a set of ChewingKeys.
g_array_free(m_parse_steps, TRUE);
}
- virtual int parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
virtual int parse (guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
};
public:
virtual ~DoublePinyinParser2 () {}
- virtual int parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
virtual int parse (guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;
public:
virtual ~ChewingParser2 () {}
- virtual int parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
+ virtual bool parse_one_key (guint32 options, ChewingKey & key, ChewingKeyRest & key_rest, const char *str, int len) const;
virtual int parse (guint32 options, ChewingKeyVector & keys, ChewingKeyRestVector & key_rests, const char *str, int len) const;