}
}
+#define ID_TO_SHENG(id) \
+ double_pinyin_map[Config::doublePinyinSchema ()].sheng[id]
+#define ID_TO_YUNS(id) \
+ double_pinyin_map[Config::doublePinyinSchema ()].yun[id]
+
inline const Pinyin *
-DoublePinyinEditor::isPinyin (gchar i)
+DoublePinyinEditor::isPinyin (gint i)
{
if ((Config::option () & PINYIN_INCOMPLETE_PINYIN) == 0) {
return NULL;
}
- gint schema = Config::doublePinyinSchema ();
- gint sheng = double_pinyin_map[schema].sheng[_id (i)];
+ gint sheng = ID_TO_SHENG (i);
if (sheng == PINYIN_ID_VOID) {
return NULL;
}
inline const Pinyin *
-DoublePinyinEditor::isPinyin (gchar i, gchar j)
+DoublePinyinEditor::isPinyin (gint i, gint j)
{
const Pinyin *pinyin = NULL;
- gint schema = Config::doublePinyinSchema ();
- gint sheng = double_pinyin_map[schema].sheng[_id (i)];
- const gint *yun = double_pinyin_map[schema].yun[_id (j)];
+ gint sheng = ID_TO_SHENG (i);
+ const gint *yun = ID_TO_YUNS (j);
if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID)
return pinyin;
DoublePinyinEditor::insert (gint ch)
{
const Pinyin *pinyin;
+ gint id;
/* is full */
if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN))
return FALSE;
- if (_id (ch) < 0) {
+ id = _id (ch);
+ if (id == -1) {
/* it is not availidate ch */
return FALSE;
}
+ if (G_UNLIKELY (m_text.isEmpty () && ID_TO_SHENG(id) == PINYIN_ID_VOID)) {
+ return FALSE;
+ }
+
m_text.insert (m_cursor++, ch);
if (m_cursor > m_pinyin_len + 2) {
do {
if (m_cursor == m_pinyin_len + 2) {
- if ((pinyin = isPinyin (m_text[m_cursor - 2], ch)) == NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 2]), id)) == NULL) {
updatePreeditText ();
updateAuxiliaryText ();
return TRUE;
pinyin = m_pinyin.back ();
if (pinyin->flags & PINYIN_INCOMPLETE_PINYIN) {
/* prev pinyin is incomplete */
- if ((pinyin = isPinyin (m_text[m_cursor - 2], ch)) != NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 2]), id)) != NULL) {
m_pinyin.pop ();
m_pinyin.append (pinyin, m_pinyin_len - 1, 2);
m_pinyin_len = m_cursor;
}
}
}
- if ((pinyin = isPinyin (ch)) == NULL) {
+ if ((pinyin = isPinyin (id)) == NULL) {
updatePreeditText ();
updateAuxiliaryText ();
return TRUE;
m_pinyin_len = m_cursor;
}
else {
- if ((pinyin = isPinyin (m_text[m_cursor - 1])) != NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 1]))) != NULL) {
m_pinyin.append (pinyin, m_cursor - 1, 1);
m_pinyin_len = m_cursor;
}
m_pinyin_len -= 1;
}
else {
- if ((pinyin = isPinyin (m_text[m_cursor - 1])) != NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 1]))) != NULL) {
m_pinyin.append (pinyin, m_cursor - 1, 1);
m_pinyin_len = m_cursor;
}
do {
const Pinyin *pinyin = NULL;
if (m_cursor == m_pinyin_len + 2) {
- if ((pinyin = isPinyin (m_text[m_cursor - 2], m_text[m_cursor - 1])) == NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 2]),
+ _id (m_text[m_cursor - 1]))) == NULL) {
updatePreeditText ();
updateAuxiliaryText ();
return TRUE;
pinyin = m_pinyin.back ();
if (pinyin->flags & PINYIN_INCOMPLETE_PINYIN) {
/* prev pinyin is incomplete */
- if ((pinyin = isPinyin (m_text[m_cursor - 2], m_text[m_cursor -1])) != NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 2]),
+ _id (m_text[m_cursor -1]))) != NULL) {
m_pinyin.pop ();
m_pinyin.append (pinyin, m_pinyin_len - 1, 2);
m_pinyin_len = m_cursor;
}
}
}
- if ((pinyin = isPinyin (m_text[m_cursor - 1])) == NULL) {
+ if ((pinyin = isPinyin (_id (m_text[m_cursor - 1]))) == NULL) {
updatePreeditText ();
updateAuxiliaryText ();
return TRUE;
const Pinyin *pinyin = NULL;
if (m_pinyin_len == m_cursor - 1) {
- pinyin = isPinyin (m_text[m_pinyin_len]);
+ pinyin = isPinyin (_id (m_text[m_pinyin_len]));
}
else {
pinyin = isPinyin (m_text[m_pinyin_len], m_text[m_pinyin_len + 1]);
if (pinyin == NULL)
- pinyin = isPinyin (m_text[m_pinyin_len]);
+ pinyin = isPinyin ( _id (m_text[m_pinyin_len]));
}
if (pinyin == NULL)
break;