ibus_engine_pinyin_c_sources = \
PYBopomofoEditor.cc \
PYBopomofoEngine.cc \
- PYPConfig.cc \
PYConfig.cc \
PYDatabase.cc \
PYDoublePinyinEditor.cc \
if IBUS_BUILD_LIBPINYIN
ibus_engine_pinyin_c_sources += \
+ PYPConfig.cc \
PYLibPinyin.cc \
PYPPhoneticEditor.cc \
PYPPinyinEditor.cc \
if (G_UNLIKELY (m_text.empty ())) {
m_pinyin_len = 0;
/* TODO: check whether to replace "" with NULL. */
- pinyin_parse_more_chewings (m_instance, "");
+ pinyin_parse_more_chewings (m_instance, NULL);
return;
}
// guint pinyin_cursor = getPinyinCursor ();
PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
for (guint i = 0; i < pinyin_keys->len; ++i) {
PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
PinyinKeyPos *pos = &g_array_index (pinyin_poses, PinyinKeyPos, i);
- guint cursor = pos->get_pos ();
+ guint cursor = pos->m_raw_begin;
if (G_UNLIKELY (cursor == m_cursor)) { /* at word boundary. */
- m_buffer << '|' << key->get_key_zhuyin_string ();
+ m_buffer << '|' << key->get_chewing_string ();
} else if (G_LIKELY ( cursor < m_cursor &&
- m_cursor < pos->get_end_pos() )) { /* in word */
+ m_cursor < pos->m_raw_end )) { /* in word */
/* raw text */
- String raw = m_text.substr (cursor, pos->get_length ());
+ String raw = m_text.substr (cursor,
+ pos->m_raw_end - pos->m_raw_begin);
guint offset = m_cursor - cursor;
m_buffer << ' ';
String before = raw.substr (0, offset);
m_buffer << bopomofo_char[keyvalToBopomofo (*iter)];
}
} else { /* other words */
- m_buffer << ' ' << key->get_key_zhuyin_string ();
+ m_buffer << ' ' << key->get_chewing_string ();
}
}
#include "PYConfig.h"
#include "PYLibPinyin.h"
-#define DEFINE_DOUBLE_PINYIN_TABLES
-#include "PYDoublePinyinTable.h"
-
using namespace PY;
/*
#define ID(c) \
((c >= IBUS_a && c <= IBUS_z) ? c - IBUS_a : (c == IBUS_semicolon ? 26 : -1))
-#define ID_TO_SHENG(id) \
- (double_pinyin_map[m_config.doublePinyinSchema ()].sheng[id])
-#define ID_TO_YUNS(id) \
- (double_pinyin_map[m_config.doublePinyinSchema ()].yun[id])
-
#define IS_ALPHA(c) \
((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return FALSE;
}
+#if 0
if (G_UNLIKELY (m_text.empty () && ID_TO_SHENG (id) == PINYIN_ID_VOID)) {
return FALSE;
}
+#endif
m_text.insert (m_cursor++, ch);
updatePinyin ();
// guint pinyin_cursor = getPinyinCursor ();
PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
for (guint i = 0; i < pinyin_keys->len; ++i) {
PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
PinyinKeyPos *pos = &g_array_index (pinyin_poses, PinyinKeyPos, i);
- guint cursor = pos->get_pos ();
+ guint cursor = pos->m_raw_begin;
if (G_UNLIKELY (cursor == m_cursor)) { /* at word boundary. */
- m_buffer << '|' << key->get_key_string ();
+ m_buffer << '|' << key->get_pinyin_string ();
} else if (G_LIKELY ( cursor < m_cursor &&
- m_cursor < pos->get_end_pos() )) { /* in word */
+ m_cursor < pos->m_raw_end )) { /* in word */
/* raw text */
- String raw = m_text.substr (cursor, pos->get_length ());
+ String raw = m_text.substr (cursor,
+ pos->m_raw_end - pos->m_raw_begin);
guint offset = m_cursor - cursor;
m_buffer << ' ' << raw.substr (0, offset)
<< '|' << raw.substr (offset);
} else { /* other words */
- m_buffer << ' ' << key->get_key_string ();
+ m_buffer << ' ' << key->get_pinyin_string ();
}
}
if (G_UNLIKELY (m_text.empty ())) {
m_pinyin_len = 0;
/* TODO: check whether to replace "" with NULL. */
- pinyin_parse_more_full_pinyins (m_instance, "");
+ pinyin_parse_more_full_pinyins (m_instance, NULL);
return;
}
- PinyinArray pinyins (MAX_PINYIN_LEN);
-
- m_pinyin_len = PinyinParser::parse (m_text, // text
- m_text.length (), // text length
- m_config.option (), // option
- pinyins, // result
- MAX_PHRASE_LEN); // max result length
-
- /* propagate to libpinyin */
- g_array_set_size (m_instance->m_pinyin_keys, 0);
- g_array_set_size (m_instance->m_pinyin_poses, 0);
-
- PinyinKey key; PinyinKeyPos pos;
- PinyinArray::const_iterator iter = pinyins.begin ();
- for ( ; iter != pinyins.end (); ++iter ) {
- PinyinSegment py = *iter;
- String pinyin = py.pinyin->sheng;
- gunichar yun_v = g_utf8_get_char("ΓΌ");
- gchar buf[7];
- for (const gchar * p = py.pinyin->yun; *p; p = g_utf8_next_char (p)){
- gunichar cur_yun = g_utf8_get_char (p);
- if (G_UNLIKELY(yun_v == cur_yun)) {
- pinyin += "v";
- } else {
- gint len = g_unichar_to_utf8 (cur_yun, buf);
- buf[len] = '\0';
- pinyin += buf;
- }
- }
- pinyin_parse_full_pinyin (m_instance, (const char *)pinyin, &key);
- pos.set_pos (py.begin); pos.set_length (py.len);
- g_array_append_val (m_instance->m_pinyin_keys, key);
- g_array_append_val (m_instance->m_pinyin_poses, pos);
- }
-
+ m_pinyin_len =
+ pinyin_parse_more_full_pinyins (m_instance, m_text.c_str ());
pinyin_guess_sentence (m_instance);
}
// guint pinyin_cursor = getPinyinCursor ();
PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
for (guint i = 0; i < pinyin_keys->len; ++i) {
PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
PinyinKeyPos *pos = &g_array_index (pinyin_poses, PinyinKeyPos, i);
- guint cursor = pos->get_pos ();
+ guint cursor = pos->m_raw_begin;
if (G_UNLIKELY (cursor == m_cursor)) { /* at word boundary. */
- m_buffer << '|' << key->get_key_string ();
+ m_buffer << '|' << key->get_pinyin_string ();
} else if (G_LIKELY ( cursor < m_cursor &&
- m_cursor < pos->get_end_pos() )) { /* in word */
+ m_cursor < pos->m_raw_end )) { /* in word */
/* raw text */
- String raw = m_text.substr (cursor, pos->get_length ());
+ String raw = m_text.substr (cursor,
+ pos->m_raw_end - pos->m_raw_begin);
guint offset = m_cursor - cursor;
m_buffer << ' ' << raw.substr (0, offset)
<< '|' << raw.substr (offset);
} else { /* other words */
- m_buffer << ' ' << key->get_key_string ();
+ m_buffer << ' ' << key->get_pinyin_string ();
}
}
LibPinyinPhoneticEditor::getPinyinCursor ()
{
/* Translate cursor position to pinyin position. */
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
guint pinyin_cursor = pinyin_poses->len;
for (size_t i = 0; i < pinyin_poses->len; ++i) {
PinyinKeyPos *pos = &g_array_index
(pinyin_poses, PinyinKeyPos, i);
- if (pos->get_pos () <= m_cursor && m_cursor < pos->get_end_pos ())
+ if (pos->m_raw_begin <= m_cursor && m_cursor < pos->m_raw_end)
pinyin_cursor = i;
}
guint8 len = pinyin_choose_candidate (m_instance, lookup_cursor, *token);
pinyin_guess_sentence (m_instance);
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
lookup_cursor += len;
if (lookup_cursor == pinyin_poses->len) {
commit();
}
PinyinKeyPos *pos = &g_array_index
(pinyin_poses, PinyinKeyPos, lookup_cursor);
- m_cursor = pos->get_pos();
+ m_cursor = pos->m_raw_begin;
return TRUE;
}
if (G_UNLIKELY (m_cursor > m_pinyin_len)) {
cursor = m_pinyin_len;
} else {
- PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
guint pinyin_cursor = getPinyinCursor ();
PinyinKeyPos *pos = &g_array_index
(pinyin_poses, PinyinKeyPos, pinyin_cursor);
- cursor = pos->m_pos;
+ cursor = pos->m_raw_begin;
/* cursor at the begin of one pinyin */
g_return_val_if_fail (pinyin_cursor > 0, 0);
if ( cursor == m_cursor) {
pos = &g_array_index
(pinyin_poses, PinyinKeyPos, pinyin_cursor - 1);
- cursor = pos->m_pos;
+ cursor = pos->m_raw_begin;
}
}
} else {
guint pinyin_cursor = getPinyinCursor ();
PinyinKeyPos *pos = &g_array_index
- (m_instance->m_pinyin_poses, PinyinKeyPos, pinyin_cursor);
- cursor = pos->get_end_pos ();
+ (m_instance->m_pinyin_key_rests, PinyinKeyPos, pinyin_cursor);
+ cursor = pos->m_raw_end;
}
return cursor;
#include <pinyin.h>
#include "PYLookupTable.h"
#include "PYEditor.h"
-#include "PYPinyinParser.h"
namespace PY {
if (G_LIKELY (i))
m_buffer << ' ';
PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
- m_buffer << key->get_key_string ();
+ m_buffer << key->get_pinyin_string ();
}
/* append rest text */