diff options
author | Hiroshi Sumita <hsumita@chromium.org> | 2011-11-15 11:22:24 +0900 |
---|---|---|
committer | Hiroshi Sumita <hsumita@chromium.org> | 2011-11-15 11:22:24 +0900 |
commit | e97b37e6e8213500e4e33252e2c6b2f02c9c8a61 (patch) | |
tree | a9de3b0491f23d0170d001d62775f5aadbe3adea | |
parent | d4a3a174b8654bdd8961158845e9aba5c9c098b7 (diff) | |
download | pyzy-e97b37e6e8213500e4e33252e2c6b2f02c9c8a61.tar.gz |
Replace variable types from g* to standard types.
replacing
- gchar - char
- gint - int, unsigned int, or size_t
- guint -> unsigned int or size_t
- guint8 -> unsigned char
- gboolean -> bool
- gsize -> size_t
- gpointer -> void *
- gconstpointer -> const void *
- gunichar -> unichar (typedef of int on PyZyUtil.h)
BUG=None
TEST=Run a test
Review URL: http://codereview.appspot.com/5367046
40 files changed, 407 insertions, 403 deletions
diff --git a/scripts/bopomofo.py b/scripts/bopomofo.py index 05f1327..6608c53 100644 --- a/scripts/bopomofo.py +++ b/scripts/bopomofo.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- ''' -const static gunichar bopomofo_char[] = { +const static unichar bopomofo_char[] = { L'\0',L'ㄅ',L'ㄆ',L'ㄇ',L'ㄈ',L'ㄉ',L'ㄊ',L'ㄋ',L'ㄌ',L'ㄍ',L'ㄎ', L'ㄏ',L'ㄐ',L'ㄑ',L'ㄒ',L'ㄓ',L'ㄔ',L'ㄕ',L'ㄖ',L'ㄗ',L'ㄘ',L'ㄙ', diff --git a/scripts/double.py b/scripts/double.py index 58ad664..4b5602b 100644 --- a/scripts/double.py +++ b/scripts/double.py @@ -1,7 +1,7 @@ import pydict for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS: - print "static const gint8 double_pinyin_%s_sheng[] = {" % name.lower() + print "static const char double_pinyin_%s_sheng[] = {" % name.lower() for c in "abcdefghijklmnopqrstuvwxyz;": s = sheng.get(c, "VOID") if s == "'": @@ -13,7 +13,7 @@ for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS: print " PINYIN_ID_%s // %s" % ((s + ",").ljust(5), c.upper()) print "};" - print "static const gint8 double_pinyin_%s_yun[][2] = {" % name.lower() + print "static const char double_pinyin_%s_yun[][2] = {" % name.lower() for c in "abcdefghijklmnopqrstuvwxyz;": s = yun.get(c, ("VOID", "VOID")) if len(s) == 1: @@ -32,8 +32,8 @@ for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS: print ''' static const struct { - const gint8 (&sheng)[27]; - const gint8 (&yun)[27][2]; + const char (&sheng)[27]; + const char (&yun)[27][2]; } double_pinyin_map [] = {''' for name, (sheng, yun) in pydict.SHUANGPIN_SCHEMAS: print " { double_pinyin_%s_sheng, double_pinyin_%s_yun}," % (name.lower(), name.lower()) diff --git a/scripts/genbopomofokeyboard.py b/scripts/genbopomofokeyboard.py index 5ad0676..2c3e94a 100644 --- a/scripts/genbopomofokeyboard.py +++ b/scripts/genbopomofokeyboard.py @@ -80,7 +80,7 @@ def tochar(ch): def gen_table(): i = 0 - print 'static const guint8' + print 'static const unsigned char' print 'bopomofo_keyboard[][41][2] = {' for keyboard in bopomofo_keyboard: print ' {' diff --git a/scripts/genpuncttable.py b/scripts/genpuncttable.py index b852ec6..4e58050 100644 --- a/scripts/genpuncttable.py +++ b/scripts/genpuncttable.py @@ -11,7 +11,7 @@ def tocstr(s): def gen_table(): array = [] i = 0 - print 'static const gchar * const' + print 'static const char * const' print 'puncts[] = {' for k, vs in punct_map: k = tocstr(k) @@ -22,7 +22,7 @@ def gen_table(): i += len(vs) + 2 print '};' print - print 'static const gchar * const * const' + print 'static const char * const * const' print 'punct_table[] = {' for i, k in array: print ' &puncts[%d], // %s' % (i, k) diff --git a/scripts/genpytable.py b/scripts/genpytable.py index 5dfe2d0..33b8da1 100644 --- a/scripts/genpytable.py +++ b/scripts/genpytable.py @@ -268,8 +268,8 @@ def gen_macros(): print def gen_option_check(name, fuzzy): - print '''static gboolean -%s (guint option, gint id, gint fid) + print '''static bool +%s (unsigned int option, int id, int fid) { switch ((id << 16) | fid) {''' % name for y1, y2 in fuzzy: diff --git a/scripts/gensimptradtable.py b/scripts/gensimptradtable.py index f0afb4e..d61dd50 100644 --- a/scripts/gensimptradtable.py +++ b/scripts/gensimptradtable.py @@ -1,7 +1,7 @@ import sctc items = sctc.S_2_T.items() items.sort() -print "const gunichar simp_to_trad[][2] = {" +print "const unichar simp_to_trad[][2] = {" for s, t in items: print " { 0x%x, 0x%x }, // %s => %s" % (ord(s), ord(t[0]), s.encode("utf8"), t[0].encode("utf8")) print "};" diff --git a/scripts/update-simptrad-table.py b/scripts/update-simptrad-table.py index 718231d..64d3d45 100755 --- a/scripts/update-simptrad-table.py +++ b/scripts/update-simptrad-table.py @@ -58,7 +58,7 @@ def get_records(): return maxlen, records def main(): - print "static const gchar *simp_to_trad[][2] = {" + print "static const char *simp_to_trad[][2] = {" maxlen, records = get_records() for s, ts in records: print ' { "%s", "%s" },' % (s, ts) diff --git a/src/PyZyBopomofoContext.cc b/src/PyZyBopomofoContext.cc index 589c28a..6c5e641 100644 --- a/src/PyZyBopomofoContext.cc +++ b/src/PyZyBopomofoContext.cc @@ -28,7 +28,7 @@ namespace PyZy { #include "PyZyBopomofoKeyboard.h" -const static gchar * bopomofo_select_keys[] = { +const static char * bopomofo_select_keys[] = { "1234567890", "asdfghjkl;", "1qaz2wsxed", @@ -116,7 +116,7 @@ BopomofoContext::removeWordBefore (void) if (G_UNLIKELY (m_cursor == 0)) return false; - guint cursor; + size_t cursor; if (G_UNLIKELY (m_cursor > m_pinyin_len)) { cursor = m_pinyin_len; @@ -271,16 +271,16 @@ BopomofoContext::updateAuxiliaryText (void) m_buffer.clear (); if (m_selected_special_phrase.empty ()) { - guint si = 0; - guint m_text_len = m_text.length(); - for (guint i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) { + size_t si = 0; + size_t m_text_len = m_text.length(); + for (size_t i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) { if (G_LIKELY (i != m_phrase_editor.cursor ())) m_buffer << ','; - m_buffer << (gunichar *)m_pinyin[i]->bopomofo; - for (guint sj = 0; m_pinyin[i]->bopomofo[sj] == bopomofo_char[keyvalToBopomofo(m_text.c_str()[si])] ; si++,sj++); + m_buffer << (unichar *)m_pinyin[i]->bopomofo; + for (size_t sj = 0; m_pinyin[i]->bopomofo[sj] == bopomofo_char[keyvalToBopomofo(m_text.c_str()[si])] ; si++,sj++); if (si < m_text_len) { - gint ch = keyvalToBopomofo(m_text.c_str()[si]); + int ch = keyvalToBopomofo(m_text.c_str()[si]); if (ch >= BOPOMOFO_TONE_2 && ch <= BOPOMOFO_TONE_5) { m_buffer.appendUnichar(bopomofo_char[ch]); ++si; @@ -289,7 +289,7 @@ BopomofoContext::updateAuxiliaryText (void) } for (String::iterator i = m_text.begin () + m_pinyin_len; i != m_text.end (); i++) { - if (m_cursor == (guint)(i - m_text.begin ())) + if (m_cursor == (size_t)(i - m_text.begin ())) m_buffer << '|'; m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*i)]); } @@ -317,7 +317,7 @@ BopomofoContext::commit (CommitType type) if (G_LIKELY (type == TYPE_CONVERTED)) { m_buffer << m_phrase_editor.selectedString (); - const gchar *p; + const char *p; if (m_selected_special_phrase.empty ()) { p = textAfterPinyin (m_buffer.utf8Length ()); @@ -328,15 +328,15 @@ BopomofoContext::commit (CommitType type) } while (*p != '\0') { - m_buffer.appendUnichar ((gunichar)bopomofo_char[keyvalToBopomofo (*p++)]); + m_buffer.appendUnichar ((unichar)bopomofo_char[keyvalToBopomofo (*p++)]); } m_phrase_editor.commit (); } else if (type == TYPE_PHONETIC) { - const gchar *p = m_text; + const char *p = m_text; while (*p != '\0') { - m_buffer.appendUnichar ((gunichar)bopomofo_char[keyvalToBopomofo (*p++)]); + m_buffer.appendUnichar ((unichar)bopomofo_char[keyvalToBopomofo (*p++)]); } } else { m_buffer = m_text; @@ -358,10 +358,10 @@ BopomofoContext::updatePreeditText (void) return; } - guint edit_begin_word = 0; - guint edit_end_word = 0; - guint edit_begin_byte = 0; - guint edit_end_byte = 0; + size_t edit_begin_word = 0; + size_t edit_end_word = 0; + size_t edit_begin_byte = 0; + size_t edit_end_byte = 0; m_buffer.clear (); m_preedit_text.clear (); @@ -383,7 +383,7 @@ BopomofoContext::updatePreeditText (void) edit_begin_byte = m_buffer.size (); if (m_candidates.size () > 0) { - guint index = m_focused_candidate; + size_t index = m_focused_candidate; if (index < m_special_phrases.size ()) { m_buffer << m_special_phrases[index].c_str (); @@ -405,13 +405,13 @@ BopomofoContext::updatePreeditText (void) edit_end_byte = m_buffer.size (); /* append rest text */ - for (const gchar *p=m_text.c_str() + m_pinyin_len; *p ;++p) { + for (const char *p=m_text.c_str() + m_pinyin_len; *p ;++p) { m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*p)]); } } else { - for (const gchar *p = m_text.c_str (); *p; ++p) { - if ((guint) (p - m_text.c_str ()) == m_cursor) + for (const char *p = m_text.c_str (); *p; ++p) { + if ((size_t) (p - m_text.c_str ()) == m_cursor) m_buffer << ' '; m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*p)]); } @@ -423,7 +423,7 @@ BopomofoContext::updatePreeditText (void) else { edit_end_word = m_buffer.utf8Length (); edit_end_byte = m_buffer.size (); - for (const gchar *p=m_text.c_str () + m_pinyin_len; *p ; ++p) { + for (const char *p=m_text.c_str () + m_pinyin_len; *p ; ++p) { m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*p)]); } } @@ -438,20 +438,20 @@ BopomofoContext::updatePreeditText (void) PhoneticContext::updatePreeditText (); } -static gint -keyboard_cmp (gconstpointer p1, gconstpointer p2) +static int +keyboard_cmp (const void * p1, const void * p2) { - const gint s1 = GPOINTER_TO_INT (p1); - const guint8 *s2 = (const guint8 *) p2; + const int s1 = GPOINTER_TO_INT (p1); + const unsigned char *s2 = (const unsigned char *) p2; return s1 - s2[0]; } -gint -BopomofoContext::keyvalToBopomofo(gint ch) +int +BopomofoContext::keyvalToBopomofo(int ch) { - const gint keyboard = m_config.bopomofoKeyboardMapping (); - const guint8 *brs; - brs = (const guint8 *) std::bsearch (GINT_TO_POINTER (ch), + const unsigned int keyboard = m_config.bopomofoKeyboardMapping (); + const unsigned char *brs; + brs = (const unsigned char *) std::bsearch (GINT_TO_POINTER (ch), bopomofo_keyboard[keyboard], G_N_ELEMENTS (bopomofo_keyboard[keyboard]), sizeof(bopomofo_keyboard[keyboard][0]), diff --git a/src/PyZyBopomofoContext.h b/src/PyZyBopomofoContext.h index 28f4841..1394cae 100644 --- a/src/PyZyBopomofoContext.h +++ b/src/PyZyBopomofoContext.h @@ -56,8 +56,8 @@ protected: virtual void updatePinyin (); virtual void updatePreeditText (); - bool processBopomofo (guint keyval, guint keycode, guint modifiers); - gint keyvalToBopomofo(gint ch); + bool processBopomofo (unsigned int keyval, unsigned int keycode, unsigned int modifiers); + int keyvalToBopomofo(int ch); }; }; diff --git a/src/PyZyBopomofoKeyboard.h b/src/PyZyBopomofoKeyboard.h index 996fb64..3384ba6 100644 --- a/src/PyZyBopomofoKeyboard.h +++ b/src/PyZyBopomofoKeyboard.h @@ -25,7 +25,7 @@ #include "PyZyBopomofo.h" -static const guint8 +static const unsigned char bopomofo_keyboard[][41][2] = { { { ',' , BOPOMOFO_E2 }, diff --git a/src/PyZyConfig.cc b/src/PyZyConfig.cc index 85e9fc0..fa95224 100644 --- a/src/PyZyConfig.cc +++ b/src/PyZyConfig.cc @@ -143,8 +143,8 @@ Config::readDefaultValues () m_impl->m_option = PINYIN_DEFAULT_OPTION; m_impl->m_option_mask = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; m_impl->m_double_pinyin_schema = 0; - m_impl->m_mode_simp = TRUE; - m_impl->m_special_phrases = TRUE; + m_impl->m_mode_simp = true; + m_impl->m_special_phrases = true; m_impl->m_bopomofo_keyboard_mapping = 0; } @@ -214,7 +214,7 @@ void BopomofoConfig::readDefaultValues (void) { Config::readDefaultValues (); - m_impl->m_special_phrases = FALSE; + m_impl->m_special_phrases = false; } }; // namespace PyZy diff --git a/src/PyZyDatabase.cc b/src/PyZyDatabase.cc index 0e730fe..6216422 100644 --- a/src/PyZyDatabase.cc +++ b/src/PyZyDatabase.cc @@ -41,6 +41,7 @@ namespace PyZy { #define USER_DICTIONARY_FILE "user-1.3.db" + std::unique_ptr<Database> Database::m_instance; class Conditions : public std::vector<std::string> { @@ -48,14 +49,14 @@ public: Conditions (void) : std::vector<std::string> (1) {} void double_ (void) { - gint i = size (); + size_t i = size (); do { push_back (at (--i)); } while (i > 0); } void triple (void) { - gint i = size (); + size_t i = size (); do { const std::string & value = std::vector<std::string>::at (--i); push_back (value); @@ -63,15 +64,15 @@ public: } while (i > 0); } - void appendVPrintf (gint begin, gint end, const gchar *fmt, va_list args) { - gchar str[64]; + void appendVPrintf (size_t begin, size_t end, const char *fmt, va_list args) { + char str[64]; g_vsnprintf (str, sizeof(str), fmt, args); - for (gint i = begin; i < end; i++) { + for (size_t i = begin; i < end; i++) { at (i) += str; } } - void appendPrintf (gint begin, gint end, const gchar *fmt, ...) { + void appendPrintf (size_t begin, size_t end, const char *fmt, ...) { va_list args; va_start (args, fmt); appendVPrintf (begin, end, fmt, args); @@ -94,36 +95,36 @@ public: } } - gboolean prepare (const String &sql) { + bool prepare (const String &sql) { if (sqlite3_prepare (m_db, sql.c_str (), sql.size (), &m_stmt, NULL) != SQLITE_OK) { g_warning ("parse sql failed!\n %s", sql.c_str ()); - return FALSE; + return false; } - return TRUE; + return true; } - gboolean step (void) { + bool step (void) { switch (sqlite3_step (m_stmt)) { case SQLITE_ROW: - return TRUE; + return true; case SQLITE_DONE: - return FALSE; + return false; default: g_warning ("sqlites step error!"); - return FALSE; + return false; } } - const gchar *columnText (guint col) { - return (const gchar *) sqlite3_column_text (m_stmt, col); + const char *columnText (int col) { + return (const char *) sqlite3_column_text (m_stmt, col); } - gint columnInt (guint col) { + int columnInt (int col) { return sqlite3_column_int (m_stmt, col); } @@ -133,9 +134,9 @@ private: }; Query::Query (const PinyinArray & pinyin, - guint pinyin_begin, - guint pinyin_len, - guint option) + size_t pinyin_begin, + size_t pinyin_len, + unsigned int option) : m_pinyin (pinyin), m_pinyin_begin (pinyin_begin), m_pinyin_len (pinyin_len), @@ -148,10 +149,10 @@ Query::~Query (void) { } -gint -Query::fill (PhraseArray &phrases, gint count) +int +Query::fill (PhraseArray &phrases, int count) { - gint row = 0; + int row = 0; while (m_pinyin_len > 0) { if (G_LIKELY (m_stmt.get () == NULL)) { @@ -169,7 +170,7 @@ Query::fill (PhraseArray &phrases, gint count) phrase.user_freq = m_stmt->columnInt (DB_COLUMN_USER_FREQ); phrase.len = m_pinyin_len; - for (guint i = 0, column = DB_COLUMN_S0; i < m_pinyin_len; i++) { + for (size_t i = 0, column = DB_COLUMN_S0; i < m_pinyin_len; i++) { phrase.pinyin_id[i].sheng = m_stmt->columnInt (column++); phrase.pinyin_id[i].yun = m_stmt->columnInt (column++); } @@ -211,36 +212,36 @@ Database::~Database (void) } } -inline gboolean -Database::executeSQL (const gchar *sql, sqlite3 *db) +inline bool +Database::executeSQL (const char *sql, sqlite3 *db) { if (db == NULL) db = m_db; - gchar *errmsg = NULL; + char *errmsg = NULL; if (sqlite3_exec (db, sql, NULL, NULL, &errmsg) != SQLITE_OK) { g_warning ("%s: %s", errmsg, sql); sqlite3_free (errmsg); - return FALSE; + return false; } - return TRUE; + return true; } -gboolean +bool Database::open (void) { do { #if (SQLITE_VERSION_NUMBER >= 3006000) sqlite3_initialize (); #endif - static const gchar * maindb [] = { + static const char * maindb [] = { PKGDATADIR"/db/local.db", PKGDATADIR"/db/open-phrase.db", PKGDATADIR"/db/android.db", "main.db", }; - guint i; + size_t i; for (i = 0; i < G_N_ELEMENTS (maindb); i++) { if (!g_file_test(maindb[i], G_FILE_TEST_IS_REGULAR)) continue; @@ -297,17 +298,17 @@ Database::open (void) /* prefetch some tables */ // prefetch (); - return TRUE; + return true; } while (0); if (m_db) { sqlite3_close (m_db); m_db = NULL; } - return FALSE; + return false; } -gboolean +bool Database::loadUserDB (void) { sqlite3 *userdb = NULL; @@ -321,7 +322,7 @@ Database::loadUserDB (void) m_buffer.clear (); m_buffer << m_user_data_dir << G_DIR_SEPARATOR_S << USER_DICTIONARY_FILE; - gint flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; + unsigned int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; if (sqlite3_open_v2 (m_buffer, &userdb, flags, NULL) != SQLITE_OK && sqlite3_open_v2 (":memory:", &userdb, flags, NULL) != SQLITE_OK) break; @@ -337,9 +338,9 @@ Database::loadUserDB (void) << "INSERT OR IGNORE INTO desc VALUES " << "('attach-time', datetime());\n"; /* create phrase tables */ - for (guint i = 0; i < MAX_PHRASE_LEN; i++) { + for (size_t i = 0; i < MAX_PHRASE_LEN; i++) { m_sql.appendPrintf ("CREATE TABLE IF NOT EXISTS py_phrase_%d (user_freq, phrase TEXT, freq INTEGER ", i); - for (guint j = 0; j <= i; j++) + for (size_t j = 0; j <= i; j++) m_sql.appendPrintf (",s%d INTEGER, y%d INTEGER", j, j); m_sql << ");\n"; } @@ -348,10 +349,10 @@ Database::loadUserDB (void) m_sql << "CREATE UNIQUE INDEX IF NOT EXISTS " << "index_0_0 ON py_phrase_0(s0,y0,phrase);\n"; m_sql << "CREATE UNIQUE INDEX IF NOT EXISTS " << "index_1_0 ON py_phrase_1(s0,y0,s1,y1,phrase);\n"; m_sql << "CREATE INDEX IF NOT EXISTS " << "index_1_1 ON py_phrase_1(s0,s1,y1);\n"; - for (guint i = 2; i < MAX_PHRASE_LEN; i++) { + for (size_t i = 2; i < MAX_PHRASE_LEN; i++) { m_sql << "CREATE UNIQUE INDEX IF NOT EXISTS " << "index_" << i << "_0 ON py_phrase_" << i << "(s0,y0"; - for (guint j = 1; j <= i; j++) + for (size_t j = 1; j <= i; j++) m_sql << ",s" << j << ",y" << j; m_sql << ",phrase);\n"; m_sql << "CREATE INDEX IF NOT EXISTS " << "index_" << i << "_1 ON py_phrase_" << i << "(s0,s1,s2,y2);\n"; @@ -369,15 +370,15 @@ Database::loadUserDB (void) } sqlite3_close (userdb); - return TRUE; + return true; } while (0); if (userdb) sqlite3_close (userdb); - return FALSE; + return false; } -gboolean +bool Database::saveUserDB (void) { g_mkdir_with_parents (m_user_data_dir, 0750); @@ -390,7 +391,7 @@ Database::saveUserDB (void) /* remove tmpfile if it exist */ g_unlink (tmpfile); - gint flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; + unsigned int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; if (sqlite3_open_v2 (tmpfile, &userdb, flags, NULL) != SQLITE_OK) break; @@ -405,21 +406,21 @@ Database::saveUserDB (void) g_rename (tmpfile, m_buffer); - return TRUE; + return true; } while (0); if (userdb != NULL) sqlite3_close (userdb); g_unlink (tmpfile); - return FALSE; + return false; } void Database::prefetch (void) { m_sql.clear (); - for (guint i = 0; i < DB_PREFETCH_LEN; i++) + for (size_t i = 0; i < DB_PREFETCH_LEN; i++) m_sql << "SELECT * FROM py_phrase_" << i << ";\n"; // g_debug ("prefetching ..."); @@ -427,21 +428,22 @@ Database::prefetch (void) // g_debug ("done"); } +// This function should be return gboolean because g_timeout_add_seconds requires it. gboolean -Database::timeoutCallback (gpointer data) +Database::timeoutCallback (void * data) { Database *self = static_cast<Database*> (data); /* Get elapsed time since last modification of database. */ - guint elapsed = (guint)g_timer_elapsed (self->m_timer, NULL); + unsigned int elapsed = (unsigned int)g_timer_elapsed (self->m_timer, NULL); if (elapsed >= DB_BACKUP_TIMEOUT && self->saveUserDB ()) { self->m_timeout_id = 0; - return FALSE; + return false; } - return TRUE; + return true; } void @@ -455,11 +457,11 @@ Database::modified (void) m_timeout_id = g_timeout_add_seconds (DB_BACKUP_TIMEOUT, Database::timeoutCallback, - static_cast<gpointer> (this)); + static_cast<void *> (this)); } -inline static gboolean -pinyin_option_check_sheng (guint option, gint id, gint fid) +inline static bool +pinyin_option_check_sheng (unsigned int option, unsigned int id, unsigned int fid) { switch ((id << 16) | fid) { case (PINYIN_ID_C << 16) | PINYIN_ID_CH: @@ -490,12 +492,12 @@ pinyin_option_check_sheng (guint option, gint id, gint fid) return (option & PINYIN_FUZZY_K_G); case (PINYIN_ID_G << 16) | PINYIN_ID_K: return (option & PINYIN_FUZZY_G_K); - default: return FALSE; + default: return false; } } -inline static gboolean -pinyin_option_check_yun (guint option, gint id, gint fid) +inline static bool +pinyin_option_check_yun (unsigned int option, unsigned int id, unsigned int fid) { switch ((id << 16) | fid) { case (PINYIN_ID_AN << 16) | PINYIN_ID_ANG: @@ -518,16 +520,16 @@ pinyin_option_check_yun (guint option, gint id, gint fid) return (option & PINYIN_FUZZY_UAN_UANG); case (PINYIN_ID_UANG << 16) | PINYIN_ID_UAN: return (option & PINYIN_FUZZY_UANG_UAN); - default: return FALSE; + default: return false; } } SQLStmtPtr Database::query (const PinyinArray &pinyin, - guint pinyin_begin, - guint pinyin_len, - gint m, - guint option) + size_t pinyin_begin, + size_t pinyin_len, + int m, + unsigned int option) { g_assert (pinyin_begin < pinyin.size ()); g_assert (pinyin_len <= pinyin.size () - pinyin_begin); @@ -536,9 +538,9 @@ Database::query (const PinyinArray &pinyin, /* prepare sql */ Conditions conditions; - for (guint i = 0; i < pinyin_len; i++) { + for (size_t i = 0; i < pinyin_len; i++) { const Pinyin *p; - gboolean fs1, fs2; + bool fs1, fs2; p = pinyin[i + pinyin_begin]; fs1 = pinyin_option_check_sheng (option, p->pinyin_id[0].sheng, p->pinyin_id[1].sheng); @@ -565,7 +567,7 @@ Database::query (const PinyinArray &pinyin, "s%d=%d", i, p->pinyin_id[2].sheng); } else { - gint len = conditions.size (); + size_t len = conditions.size (); conditions.triple (); conditions.appendPrintf (0, len, "s%d=%d", i, p->pinyin_id[0].sheng); @@ -618,7 +620,7 @@ Database::query (const PinyinArray &pinyin, m_buffer.clear (); - for (guint i = 0; i < conditions.size (); i++) { + for (size_t i = 0; i < conditions.size (); i++) { if (G_UNLIKELY (i == 0)) m_buffer << " (" << conditions[i] << ")\n"; else @@ -626,7 +628,7 @@ Database::query (const PinyinArray &pinyin, } m_sql.clear (); - gint id = pinyin_len - 1; + int id = pinyin_len - 1; m_sql << "SELECT * FROM (" "SELECT 0 AS user_freq, * FROM main.py_phrase_" << id << " WHERE " << m_buffer << " UNION ALL " "SELECT * FROM userdb.py_phrase_" << id << " WHERE " << m_buffer << ") " @@ -653,7 +655,7 @@ Database::phraseWhereSql (const Phrase & p, String & sql) sql << " WHERE"; sql << " s0=" << p.pinyin_id[0].sheng << " AND y0=" << p.pinyin_id[0].yun; - for (guint i = 1; i < p.len; i++) { + for (size_t i = 1; i < p.len; i++) { sql << " AND s" << i << '=' << p.pinyin_id[i].sheng << " AND y" << i << '=' << p.pinyin_id[i].yun; } @@ -669,7 +671,7 @@ Database::phraseSql (const Phrase & p, String & sql) << ",\"" << p.phrase << '"' /* phrase */ << ',' << p.freq; /* freq */ - for (guint i = 0; i < p.len; i++) { + for (size_t i = 0; i < p.len; i++) { sql << ',' << p.pinyin_id[i].sheng << ',' << p.pinyin_id[i].yun; } @@ -688,7 +690,7 @@ Database::commit (const PhraseArray &phrases) Phrase phrase = {""}; m_sql = "BEGIN TRANSACTION;\n"; - for (guint i = 0; i < phrases.size (); i++) { + for (size_t i = 0; i < phrases.size (); i++) { phrase += phrases[i]; phraseSql (phrases[i], m_sql); } diff --git a/src/PyZyDatabase.h b/src/PyZyDatabase.h index cf13dd0..0d49d2a 100644 --- a/src/PyZyDatabase.h +++ b/src/PyZyDatabase.h @@ -42,17 +42,17 @@ class Database; class Query { public: Query (const PinyinArray & pinyin, - guint pinyin_begin, - guint pinyin_len, - guint option); + size_t pinyin_begin, + size_t pinyin_len, + unsigned int option); ~Query (void); - gint fill (PhraseArray &phrases, gint count); + int fill (PhraseArray &phrases, int count); private: const PinyinArray & m_pinyin; - guint m_pinyin_begin; - guint m_pinyin_len; - guint m_option; + size_t m_pinyin_begin; + size_t m_pinyin_len; + unsigned int m_option; SQLStmtPtr m_stmt; }; @@ -66,10 +66,10 @@ public: static void init (const std::string & data_dir); SQLStmtPtr query (const PinyinArray & pinyin, - guint pinyin_begin, - guint pinyin_len, - gint m, - guint option); + size_t pinyin_begin, + size_t pinyin_len, + int m, + unsigned int option); void commit (const PhraseArray & phrases); void remove (const Phrase & phrase); @@ -86,22 +86,22 @@ public: } private: - gboolean open (void); - gboolean loadUserDB (void); - gboolean saveUserDB (void); + bool open (void); + bool loadUserDB (void); + bool saveUserDB (void); void prefetch (void); void phraseSql (const Phrase & p, String & sql); void phraseWhereSql (const Phrase & p, String & sql); - gboolean executeSQL (const gchar *sql, sqlite3 *db = NULL); + bool executeSQL (const char *sql, sqlite3 *db = NULL); void modified (void); - static gboolean timeoutCallback (gpointer data); + static gboolean timeoutCallback (void * data); private: sqlite3 *m_db; /* sqlite3 database */ String m_sql; /* sql stmt */ String m_buffer; /* temp buffer */ - guint m_timeout_id; + unsigned int m_timeout_id; GTimer *m_timer; String m_user_data_dir; diff --git a/src/PyZyDoublePinyinContext.cc b/src/PyZyDoublePinyinContext.cc index fce7664..a376622 100644 --- a/src/PyZyDoublePinyinContext.cc +++ b/src/PyZyDoublePinyinContext.cc @@ -56,7 +56,7 @@ DoublePinyinContext::~DoublePinyinContext () bool DoublePinyinContext::insert (char ch) { - gint id; + int id; /* is full */ if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) return true; @@ -323,13 +323,13 @@ DoublePinyinContext::moveCursorToEnd (void) } inline const Pinyin * -DoublePinyinContext::isPinyin (gint i) +DoublePinyinContext::isPinyin (int i) { if ((m_config.option () & PINYIN_INCOMPLETE_PINYIN) == 0) { return NULL; } - gint8 sheng = ID_TO_SHENG (i); + char sheng = ID_TO_SHENG (i); if (sheng == PINYIN_ID_VOID) { return NULL; @@ -339,11 +339,11 @@ DoublePinyinContext::isPinyin (gint i) } inline const Pinyin * -DoublePinyinContext::isPinyin (gint i, gint j) +DoublePinyinContext::isPinyin (int i, int j) { const Pinyin *pinyin; - gint8 sheng = ID_TO_SHENG (i); - const gint8 *yun = ID_TO_YUNS (j); + char sheng = ID_TO_SHENG (i); + const char *yun = ID_TO_YUNS (j); if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID) return NULL; @@ -386,7 +386,7 @@ DoublePinyinContext::isPinyin (gint i, gint j) inline bool DoublePinyinContext::updatePinyin (bool all) { - gboolean retval = false; + bool retval = false; if (all && (m_pinyin_len != 0 || !m_pinyin.empty ())) { @@ -408,7 +408,7 @@ DoublePinyinContext::updatePinyin (bool all) } if (m_pinyin_len < m_cursor) { - guint len = m_pinyin_len; + size_t len = m_pinyin_len; if (m_pinyin.empty () == false && m_pinyin.back ()->flags & PINYIN_INCOMPLETE_PINYIN) { const Pinyin *pinyin = isPinyin (ID (m_text[m_pinyin_len -1]),ID (m_text[m_pinyin_len])); diff --git a/src/PyZyDoublePinyinContext.h b/src/PyZyDoublePinyinContext.h index 5dcdb4c..f8b18ce 100644 --- a/src/PyZyDoublePinyinContext.h +++ b/src/PyZyDoublePinyinContext.h @@ -52,8 +52,8 @@ protected: virtual bool updatePinyin (bool all); private: - const Pinyin *isPinyin (gint i, gint j); - const Pinyin *isPinyin (gint i); + const Pinyin *isPinyin (int i, int j); + const Pinyin *isPinyin (int i); }; diff --git a/src/PyZyDoublePinyinTable.h b/src/PyZyDoublePinyinTable.h index 28ec0ef..16bf908 100644 --- a/src/PyZyDoublePinyinTable.h +++ b/src/PyZyDoublePinyinTable.h @@ -34,7 +34,7 @@ #define PINYIN_ID_AEO PINYIN_ID_ZERO -static const gint8 double_pinyin_mspy_sheng[] = { +static const char double_pinyin_mspy_sheng[] = { PINYIN_ID_AEO, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -63,7 +63,7 @@ static const gint8 double_pinyin_mspy_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_mspy_yun[][2] = { +static const char double_pinyin_mspy_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_OU, PINYIN_ID_VOID }, // B { PINYIN_ID_IAO, PINYIN_ID_VOID }, // C @@ -92,7 +92,7 @@ static const gint8 double_pinyin_mspy_yun[][2] = { { PINYIN_ID_EI, PINYIN_ID_VOID }, // Z { PINYIN_ID_ING, PINYIN_ID_VOID }, // ; }; -static const gint8 double_pinyin_zrm_sheng[] = { +static const char double_pinyin_zrm_sheng[] = { PINYIN_ID_AEO, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -121,7 +121,7 @@ static const gint8 double_pinyin_zrm_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_zrm_yun[][2] = { +static const char double_pinyin_zrm_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_OU, PINYIN_ID_VOID }, // B { PINYIN_ID_IAO, PINYIN_ID_VOID }, // C @@ -150,7 +150,7 @@ static const gint8 double_pinyin_zrm_yun[][2] = { { PINYIN_ID_EI, PINYIN_ID_VOID }, // Z { PINYIN_ID_VOID, PINYIN_ID_VOID }, // ; }; -static const gint8 double_pinyin_abc_sheng[] = { +static const char double_pinyin_abc_sheng[] = { PINYIN_ID_ZH, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -179,7 +179,7 @@ static const gint8 double_pinyin_abc_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_abc_yun[][2] = { +static const char double_pinyin_abc_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_OU, PINYIN_ID_VOID }, // B { PINYIN_ID_IN, PINYIN_ID_UAI }, // C @@ -208,7 +208,7 @@ static const gint8 double_pinyin_abc_yun[][2] = { { PINYIN_ID_IAO, PINYIN_ID_VOID }, // Z { PINYIN_ID_VOID, PINYIN_ID_VOID }, // ; }; -static const gint8 double_pinyin_zgpy_sheng[] = { +static const char double_pinyin_zgpy_sheng[] = { PINYIN_ID_CH, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -237,7 +237,7 @@ static const gint8 double_pinyin_zgpy_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_zgpy_yun[][2] = { +static const char double_pinyin_zgpy_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_IAO, PINYIN_ID_VOID }, // B { PINYIN_ID_VOID, PINYIN_ID_VOID }, // C @@ -266,7 +266,7 @@ static const gint8 double_pinyin_zgpy_yun[][2] = { { PINYIN_ID_OU, PINYIN_ID_VOID }, // Z { PINYIN_ID_ING, PINYIN_ID_VOID }, // ; }; -static const gint8 double_pinyin_pyjj_sheng[] = { +static const char double_pinyin_pyjj_sheng[] = { PINYIN_ID_ZERO, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -295,7 +295,7 @@ static const gint8 double_pinyin_pyjj_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_pyjj_yun[][2] = { +static const char double_pinyin_pyjj_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_IA, PINYIN_ID_UA }, // B { PINYIN_ID_UAN, PINYIN_ID_VOID }, // C @@ -324,7 +324,7 @@ static const gint8 double_pinyin_pyjj_yun[][2] = { { PINYIN_ID_UN, PINYIN_ID_VOID }, // Z { PINYIN_ID_VOID, PINYIN_ID_VOID }, // ; }; -static const gint8 double_pinyin_xhe_sheng[] = { +static const char double_pinyin_xhe_sheng[] = { PINYIN_ID_AEO, // A PINYIN_ID_B, // B PINYIN_ID_C, // C @@ -353,7 +353,7 @@ static const gint8 double_pinyin_xhe_sheng[] = { PINYIN_ID_Z, // Z PINYIN_ID_VOID, // ; }; -static const gint8 double_pinyin_xhe_yun[][2] = { +static const char double_pinyin_xhe_yun[][2] = { { PINYIN_ID_A, PINYIN_ID_VOID }, // A { PINYIN_ID_IN, PINYIN_ID_VOID }, // B { PINYIN_ID_AO, PINYIN_ID_VOID }, // C @@ -384,8 +384,8 @@ static const gint8 double_pinyin_xhe_yun[][2] = { }; static const struct { - const gint8 (&sheng)[27]; - const gint8 (&yun)[27][2]; + const char (&sheng)[27]; + const char (&yun)[27][2]; } double_pinyin_map [] = { { double_pinyin_mspy_sheng, double_pinyin_mspy_yun }, { double_pinyin_zrm_sheng, double_pinyin_zrm_yun }, diff --git a/src/PyZyDynamicSpecialPhrase.cc b/src/PyZyDynamicSpecialPhrase.cc index 7ca6c7e..e4558e8 100644 --- a/src/PyZyDynamicSpecialPhrase.cc +++ b/src/PyZyDynamicSpecialPhrase.cc @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ +#include <glib.h> #include "PyZyDynamicSpecialPhrase.h" namespace PyZy { @@ -39,7 +40,7 @@ DynamicSpecialPhrase::text (void) size_t pos = 0; size_t pnext; - gint s = 0; + int s = 0; while (s != 2) { switch (s) { case 0: // expect "${" @@ -75,23 +76,23 @@ DynamicSpecialPhrase::text (void) } inline const std::string -DynamicSpecialPhrase::dec (gint d, const gchar *fmt) +DynamicSpecialPhrase::dec (int d, const char *fmt) { - gchar string [32]; + char string [32]; g_snprintf (string, sizeof (string), fmt, d); return string; } inline const std::string -DynamicSpecialPhrase::year_cn (gboolean yy) +DynamicSpecialPhrase::year_cn (bool yy) { - static const gchar * const digits[] = { + static const char * const digits[] = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; - gint year = m_time.tm_year + 1900; - gint bit = 0; + int year = m_time.tm_year + 1900; + int bit = 0; if (yy) { year %= 100; bit = 2; @@ -109,7 +110,7 @@ DynamicSpecialPhrase::year_cn (gboolean yy) inline const std::string DynamicSpecialPhrase::month_cn (void) { - static const gchar * const month_num[] = { + static const char * const month_num[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" }; @@ -119,16 +120,16 @@ DynamicSpecialPhrase::month_cn (void) inline const std::string DynamicSpecialPhrase::weekday_cn (void) { - static const gchar * const week_num[] = { + static const char * const week_num[] = { "日", "一", "二", "三", "四", "五", "六" }; return week_num[m_time.tm_wday]; } inline const std::string -DynamicSpecialPhrase::hour_cn (guint i) +DynamicSpecialPhrase::hour_cn (unsigned int i) { - static const gchar * const hour_num[] = { + static const char * const hour_num[] = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", @@ -153,19 +154,19 @@ DynamicSpecialPhrase::halfhour_cn (void) inline const std::string DynamicSpecialPhrase::day_cn (void) { - static const gchar * const day_num[] = { + static const char * const day_num[] = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "", "十","二十", "三十" }; - guint day = m_time.tm_mday; + unsigned int day = m_time.tm_mday; return std::string (day_num[day / 10 + 10]) + day_num[day % 10]; } inline const std::string -DynamicSpecialPhrase::minsec_cn (guint i) +DynamicSpecialPhrase::minsec_cn (unsigned int i) { - static const gchar * const num[] = { + static const char * const num[] = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "零", "十","二十", "三十", "四十" @@ -190,7 +191,7 @@ DynamicSpecialPhrase::variable (const std::string &name) if (name == "minute") return dec (m_time.tm_min, "%02d"); if (name == "second") return dec (m_time.tm_sec, "%02d"); if (name == "year_cn") return year_cn (); - if (name == "year_yy_cn") return year_cn (TRUE); + if (name == "year_yy_cn") return year_cn (true); if (name == "month_cn") return month_cn (); if (name == "day_cn") return day_cn (); if (name == "weekday_cn") return weekday_cn (); diff --git a/src/PyZyDynamicSpecialPhrase.h b/src/PyZyDynamicSpecialPhrase.h index 2d04f26..2d84218 100644 --- a/src/PyZyDynamicSpecialPhrase.h +++ b/src/PyZyDynamicSpecialPhrase.h @@ -24,27 +24,26 @@ #include <ctime> #include <string> -#include <glib.h> #include "PyZySpecialPhrase.h" namespace PyZy { class DynamicSpecialPhrase : public SpecialPhrase { public: - DynamicSpecialPhrase (const std::string &text, guint pos) : + DynamicSpecialPhrase (const std::string &text, size_t pos) : SpecialPhrase (pos), m_text (text) { } ~DynamicSpecialPhrase (void); std::string text (void); - const std::string dec (gint d, const gchar *fmt = "%d"); - const std::string year_cn (gboolean yy = FALSE); + const std::string dec (int d, const char *fmt = "%d"); + const std::string year_cn (bool yy = false); const std::string month_cn (void); const std::string weekday_cn (void); - const std::string hour_cn (guint i); + const std::string hour_cn (unsigned int i); const std::string fullhour_cn (void); const std::string halfhour_cn (void); const std::string day_cn (void); - const std::string minsec_cn (guint i); + const std::string minsec_cn (unsigned int i); const std::string variable (const std::string &name); private: diff --git a/src/PyZyFullPinyinContext.cc b/src/PyZyFullPinyinContext.cc index ee069ae..0e8f4d3 100644 --- a/src/PyZyFullPinyinContext.cc +++ b/src/PyZyFullPinyinContext.cc @@ -97,7 +97,7 @@ FullPinyinContext::removeWordBefore (void) if (G_UNLIKELY (m_cursor == 0)) return false; - guint cursor; + size_t cursor; if (G_UNLIKELY (m_cursor > m_pinyin_len)) { cursor = m_pinyin_len; diff --git a/src/PyZyInputContext.h b/src/PyZyInputContext.h index c26ee57..baee186 100644 --- a/src/PyZyInputContext.h +++ b/src/PyZyInputContext.h @@ -78,10 +78,10 @@ public: virtual bool moveCursorToBegin (void) = 0; virtual bool moveCursorToEnd (void) = 0; - virtual bool selectCandidate (unsigned int index) = 0; + virtual bool selectCandidate (size_t index) = 0; virtual bool focusCandidatePrevious (void) = 0; virtual bool focusCandidateNext (void) = 0; - virtual bool resetCandidate (unsigned int index) = 0; + virtual bool resetCandidate (size_t index) = 0; virtual bool unselectCandidates () = 0; virtual bool removeCharBefore (void) = 0; @@ -106,8 +106,8 @@ public: virtual std::string restText (void) const = 0; virtual std::string auxiliaryText (void) const = 0; virtual std::vector<Candidate> candidates () const = 0; - virtual unsigned int cursor () const = 0; - virtual unsigned int focusedCandidate () const = 0; + virtual size_t cursor () const = 0; + virtual size_t focusedCandidate () const = 0; }; }; // namespace PyZy diff --git a/src/PyZyPhoneticContext.cc b/src/PyZyPhoneticContext.cc index 13ba387..b87931d 100644 --- a/src/PyZyPhoneticContext.cc +++ b/src/PyZyPhoneticContext.cc @@ -41,7 +41,7 @@ PhoneticContext::~PhoneticContext () bool PhoneticContext::updateSpecialPhrases (void) { - guint size = m_special_phrases.size (); + size_t size = m_special_phrases.size (); m_special_phrases.clear (); if (!m_config.specialPhrases ()) @@ -50,8 +50,8 @@ PhoneticContext::updateSpecialPhrases (void) if (!m_selected_special_phrase.empty ()) return false; - guint begin = m_phrase_editor.cursorInChar (); - guint end = m_cursor; + size_t begin = m_phrase_editor.cursorInChar (); + size_t end = m_cursor; if (begin < end) { SpecialPhraseTable::instance ().lookup ( @@ -80,7 +80,7 @@ PhoneticContext::updateLookupTable (void) { m_candidates.clear (); - for (gint i = 0; i < m_special_phrases.size (); ++i) { + for (size_t i = 0; i < m_special_phrases.size (); ++i) { Candidate candidate; candidate.text = m_special_phrases[i]; candidate.type = SPECIAL_PHRASE; @@ -88,7 +88,7 @@ PhoneticContext::updateLookupTable (void) } const PhraseArray & phrase_array = m_phrase_editor.candidates (); - for (gint i = 0; i < phrase_array.size (); ++i) { + for (size_t i = 0; i < phrase_array.size (); ++i) { CandidateType candidate_type; if (i < m_special_phrases.size ()) { @@ -155,7 +155,7 @@ PhoneticContext::focusCandidateNext () } bool -PhoneticContext::focusCandidate (unsigned int i) +PhoneticContext::focusCandidate (size_t i) { if (G_UNLIKELY (i >= m_candidates.size ())) { g_warning ("Too big index. Can't focus to selected candidate."); @@ -177,7 +177,7 @@ PhoneticContext::update () } bool -PhoneticContext::selectCandidate (unsigned int i) +PhoneticContext::selectCandidate (size_t i) { if (i >= m_candidates.size ()) { g_warning ("selectCandidate(%ud): Too big index!\n", i); @@ -216,7 +216,7 @@ PhoneticContext::selectCandidate (unsigned int i) } bool -PhoneticContext::resetCandidate (unsigned int i) +PhoneticContext::resetCandidate (size_t i) { if (i < m_special_phrases.size ()) { return false; diff --git a/src/PyZyPhoneticContext.h b/src/PyZyPhoneticContext.h index e1a62e6..7510b66 100644 --- a/src/PyZyPhoneticContext.h +++ b/src/PyZyPhoneticContext.h @@ -53,11 +53,11 @@ public: /* API of InputContext */ virtual void reset (void); - bool selectCandidate (unsigned int i); - bool focusCandidate (unsigned int i); + bool selectCandidate (size_t i); + bool focusCandidate (size_t i); bool focusCandidatePrevious (); bool focusCandidateNext (); - bool resetCandidate (unsigned int i); + bool resetCandidate (size_t i); bool unselectCandidates (); /* inline functions */ @@ -70,8 +70,8 @@ public: virtual std::string restText (void) const { return m_preedit_text.rest_text; } virtual std::string auxiliaryText (void) const { return m_auxiliary_text; } virtual std::vector<Candidate> candidates () const { return m_candidates; } - virtual unsigned int cursor () const { return m_cursor; } - virtual unsigned int focusedCandidate () const { return m_focused_candidate; } + virtual size_t cursor () const { return m_cursor; } + virtual size_t focusedCandidate () const { return m_focused_candidate; } protected: virtual void resetContext (void); @@ -89,31 +89,31 @@ protected: m_phrase_editor.update (m_pinyin); } - const gchar * textAfterPinyin () const + const char * textAfterPinyin () const { - return (const gchar *)m_text + m_pinyin_len; + return (const char *)m_text + m_pinyin_len; } - const gchar * textAfterPinyin (guint i) const + const char * textAfterPinyin (size_t i) const { g_assert (i <= m_pinyin.size ()); if ( G_UNLIKELY (i == 0)) return m_text; i--; - return (const gchar *)m_text + m_pinyin[i].begin + m_pinyin[i].len; + return (const char *)m_text + m_pinyin[i].begin + m_pinyin[i].len; } - const gchar * textAfterCursor () const + const char * textAfterCursor () const { - return (const gchar *)m_text + m_cursor; + return (const char *)m_text + m_cursor; } /* variables */ Config &m_config; - guint m_cursor; - guint m_focused_candidate; + size_t m_cursor; + size_t m_focused_candidate; PinyinArray m_pinyin; - guint m_pinyin_len; + size_t m_pinyin_len; String m_buffer; PhraseEditor m_phrase_editor; std::vector<std::string> m_special_phrases; diff --git a/src/PyZyPhrase.h b/src/PyZyPhrase.h index 8355e31..1df1a50 100644 --- a/src/PyZyPhrase.h +++ b/src/PyZyPhrase.h @@ -30,14 +30,14 @@ namespace PyZy { #define PHRASE_LEN_IN_BYTE (MAX_UTF8_LEN * (MAX_PHRASE_LEN + 1)) struct Phrase { - gchar phrase[PHRASE_LEN_IN_BYTE]; - guint freq; - guint user_freq; + char phrase[PHRASE_LEN_IN_BYTE]; + unsigned int freq; + unsigned int user_freq; struct { - guint8 sheng; - guint8 yun; + unsigned char sheng; + unsigned char yun; } pinyin_id[MAX_PHRASE_LEN]; - guint len; + size_t len; void reset (void) { @@ -47,7 +47,7 @@ struct Phrase { len = 0; } - gboolean empty (void) const + bool empty (void) const { return len == 0; } @@ -61,7 +61,7 @@ struct Phrase { return *this; } - operator const gchar * (void) const + operator const char * (void) const { return phrase; } diff --git a/src/PyZyPhraseEditor.cc b/src/PyZyPhraseEditor.cc index 71ff215..047fa79 100644 --- a/src/PyZyPhraseEditor.cc +++ b/src/PyZyPhraseEditor.cc @@ -41,7 +41,7 @@ PhraseEditor::~PhraseEditor (void) { } -gboolean +bool PhraseEditor::update (const PinyinArray &pinyin) { /* the size of pinyin must not bigger than MAX_PHRASE_LEN */ @@ -54,16 +54,16 @@ PhraseEditor::update (const PinyinArray &pinyin) m_selected_phrases.clear (); m_selected_string.truncate (0); updateCandidates (); - return TRUE; + return true; } -gboolean -PhraseEditor::resetCandidate (guint i) +bool +PhraseEditor::resetCandidate (size_t i) { Database::instance ().remove (m_candidates[i]); updateCandidates (); - return TRUE; + return true; } void @@ -73,11 +73,11 @@ PhraseEditor::commit (void) reset (); } -gboolean -PhraseEditor::selectCandidate (guint i) +bool +PhraseEditor::selectCandidate (size_t i) { if (G_UNLIKELY (i >= m_candidates.size ())) - return FALSE; + return false; if (G_LIKELY (i == 0)) { m_selected_phrases.insert (m_selected_phrases.end (), @@ -99,7 +99,7 @@ PhraseEditor::selectCandidate (guint i) } updateCandidates (); - return TRUE; + return true; } void @@ -115,7 +115,7 @@ PhraseEditor::updateCandidates (void) if (G_LIKELY (m_candidate_0_phrases.size () > 1)) { Phrase phrase; phrase.reset (); - for (guint i = 0; i < m_candidate_0_phrases.size (); i++) + for (size_t i = 0; i < m_candidate_0_phrases.size (); i++) phrase += m_candidate_0_phrases[i]; m_candidates.push_back (phrase); } @@ -130,8 +130,8 @@ PhraseEditor::updateCandidates (void) void PhraseEditor::updateTheFirstCandidate (void) { - guint begin; - guint end; + size_t begin; + size_t end; m_candidate_0_phrases.clear (); @@ -142,7 +142,7 @@ PhraseEditor::updateTheFirstCandidate (void) end = m_pinyin.size (); while (begin != end) { - gint ret; + int ret; Query query (m_pinyin, begin, end - begin, @@ -153,21 +153,21 @@ PhraseEditor::updateTheFirstCandidate (void) } } -gboolean +bool PhraseEditor::fillCandidates (void) { if (G_UNLIKELY (m_query.get () == NULL)) { - return FALSE; + return false; } - gint ret = m_query->fill (m_candidates, FILL_GRAN); + int ret = m_query->fill (m_candidates, FILL_GRAN); if (G_UNLIKELY (ret < FILL_GRAN)) { /* got all candidates from query */ m_query.reset (); } - return ret > 0 ? TRUE : FALSE; + return ret > 0 ? true : false; } }; // namespace PyZy diff --git a/src/PyZyPhraseEditor.h b/src/PyZyPhraseEditor.h index d59e068..28923a9 100644 --- a/src/PyZyPhraseEditor.h +++ b/src/PyZyPhraseEditor.h @@ -43,47 +43,47 @@ public: const String & selectedString (void) const { return m_selected_string; } const PinyinArray & pinyin (void) const { return m_pinyin; } const PhraseArray & candidates (void) const { return m_candidates; } - guint cursor (void) const { return m_cursor; } + size_t cursor (void) const { return m_cursor; } - guint cursorInChar (void) const + size_t cursorInChar (void) const { return m_cursor == 0 ? 0 : m_pinyin[m_cursor - 1].begin + m_pinyin[m_cursor - 1].len; } - gboolean pinyinExistsAfterCursor (void) const + bool pinyinExistsAfterCursor (void) const { return m_pinyin.size () > m_cursor; } - const Phrase & candidate (guint i) const + const Phrase & candidate (size_t i) const { return m_candidates[i]; } - gboolean fillCandidates (void); + bool fillCandidates (void); const PhraseArray & candidate0 (void) const { return m_candidate_0_phrases; } - gboolean candidateIsUserPhrase (guint i) const + bool candidateIsUserPhrase (size_t i) const { const Phrase & phrase = m_candidates[i]; return phrase.len > 1 && phrase.user_freq > 0 && phrase.freq == 0; } - gboolean unselectCandidates (void) + bool unselectCandidates (void) { if (m_cursor == 0) { - return FALSE; + return false; } else { m_selected_phrases.clear (); m_selected_string.truncate (0); m_cursor = 0; updateCandidates (); - return TRUE; + return true; } } @@ -98,17 +98,17 @@ public: m_query.reset (); } - gboolean update (const PinyinArray &pinyin); - gboolean selectCandidate (guint i); - gboolean resetCandidate (guint i); + bool update (const PinyinArray &pinyin); + bool selectCandidate (size_t i); + bool resetCandidate (size_t i); void commit (void); - gboolean empty (void) const + bool empty (void) const { return m_selected_string.empty () && m_candidate_0_phrases.empty (); } - operator gboolean (void) const + operator bool (void) const { return !empty (); } @@ -123,7 +123,7 @@ private: String m_selected_string; // selected phrases, in string format PhraseArray m_candidate_0_phrases; // the first candidate in phrase array format PinyinArray m_pinyin; - guint m_cursor; + size_t m_cursor; std::shared_ptr<Query> m_query; Config & m_config; }; diff --git a/src/PyZyPinyinArray.h b/src/PyZyPinyinArray.h index c69ac8e..1350de4 100644 --- a/src/PyZyPinyinArray.h +++ b/src/PyZyPinyinArray.h @@ -29,10 +29,10 @@ namespace PyZy { struct PinyinSegment { const Pinyin *pinyin; - guint begin; - guint len; + size_t begin; + size_t len; - PinyinSegment (const Pinyin *pinyin = NULL, guint begin = 0, guint len = 0) + PinyinSegment (const Pinyin *pinyin = NULL, size_t begin = 0, size_t len = 0) : pinyin (pinyin), begin (begin), len (len) { } operator const Pinyin * (void) const @@ -45,12 +45,12 @@ struct PinyinSegment { return pinyin; } - gboolean operator == (const PinyinSegment & p) const + bool operator == (const PinyinSegment & p) const { return (pinyin == p.pinyin) && (begin == p.begin) && (len == p.len); } - gboolean operator == (const Pinyin *p) const + bool operator == (const Pinyin *p) const { return pinyin == p; } @@ -58,12 +58,12 @@ struct PinyinSegment { class PinyinArray: public std::vector<PinyinSegment> { public: - PinyinArray (guint init_size = 0) + PinyinArray (size_t init_size = 0) { std::vector<PinyinSegment>::reserve (init_size); } - void append (const Pinyin *pinyin, guint begin, guint len) + void append (const Pinyin *pinyin, size_t begin, size_t len) { push_back (PinyinSegment (pinyin, begin, len)); } diff --git a/src/PyZyPinyinContext.cc b/src/PyZyPinyinContext.cc index dead5f2..9641f36 100644 --- a/src/PyZyPinyinContext.cc +++ b/src/PyZyPinyinContext.cc @@ -24,7 +24,7 @@ namespace PyZy { -PinyinContext::PinyinContext (Config & config, PhoneticContext::Observer *observer) +PinyinContext::PinyinContext (Config & config, PhoneticContext::Observer * observer) : PhoneticContext (config, observer) { } @@ -44,7 +44,7 @@ PinyinContext::commit (CommitType type) if (G_LIKELY(type == TYPE_CONVERTED)) { m_buffer << m_phrase_editor.selectedString (); - const gchar *p; + const char *p; if (m_selected_special_phrase.empty ()) { p = textAfterPinyin (m_buffer.utf8Length ()); @@ -76,10 +76,10 @@ PinyinContext::updatePreeditText () return; } - guint edit_begin_word = 0; - guint edit_end_word = 0; - guint edit_begin_byte = 0; - guint edit_end_byte = 0; + size_t edit_begin_word = 0; + size_t edit_end_word = 0; + size_t edit_begin_byte = 0; + size_t edit_end_byte = 0; m_buffer.clear (); m_preedit_text.clear (); @@ -101,8 +101,8 @@ PinyinContext::updatePreeditText () edit_begin_byte = m_buffer.size (); if (m_candidates.size () > 0) { - guint index = m_focused_candidate; - + size_t index = m_focused_candidate; + if (index < m_special_phrases.size ()) { m_buffer << m_special_phrases[index]; edit_end_word = m_buffer.utf8Length (); @@ -126,11 +126,11 @@ PinyinContext::updatePreeditText () m_buffer << textAfterPinyin (edit_end_word); } else { - guint candidate_end = edit_begin_word + candidate.len; + size_t candidate_end = edit_begin_word + candidate.len; m_buffer << m_pinyin[edit_begin_word]->sheng << m_pinyin[edit_begin_word]->yun; - for (guint i = edit_begin_word + 1; i < candidate_end; i++) { + for (size_t i = edit_begin_word + 1; i < candidate_end; i++) { m_buffer << ' ' << m_pinyin[i]->sheng << m_pinyin[i]->yun; } m_buffer << '|' << textAfterPinyin (candidate_end); @@ -167,12 +167,12 @@ PinyinContext::updateAuxiliaryText (void) if (m_selected_special_phrase.empty ()) { if (m_focused_candidate < m_special_phrases.size ()) { - guint begin = m_phrase_editor.cursorInChar (); + size_t begin = m_phrase_editor.cursorInChar (); m_buffer << m_text.substr (begin, m_cursor - begin) << '|' << textAfterCursor (); } else { - for (guint i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) { + for (size_t i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) { if (G_LIKELY (i != m_phrase_editor.cursor ())) m_buffer << ' '; const Pinyin *p = m_pinyin[i]; diff --git a/src/PyZyPinyinContext.h b/src/PyZyPinyinContext.h index 701f253..41a8fe8 100644 --- a/src/PyZyPinyinContext.h +++ b/src/PyZyPinyinContext.h @@ -28,7 +28,7 @@ namespace PyZy { class PinyinContext : public PhoneticContext { public: - PinyinContext (Config & config, PhoneticContext::Observer *observer); + PinyinContext (Config &config, PhoneticContext::Observer *observer); virtual ~PinyinContext (void); virtual void commit (CommitType type); diff --git a/src/PyZyPinyinParser.cc b/src/PyZyPinyinParser.cc index f8b3d80..f9000a9 100644 --- a/src/PyZyPinyinParser.cc +++ b/src/PyZyPinyinParser.cc @@ -29,39 +29,40 @@ namespace PyZy { #include "PyZyBopomofo.h" #include "PyZyPinyinParserTable.h" -static gboolean -check_flags (const Pinyin *pinyin, guint option) +static bool +check_flags (const Pinyin *pinyin, unsigned int option) { if (pinyin == NULL) - return FALSE; + return false; if (pinyin->flags != 0) { - guint flags; + unsigned int flags; flags = pinyin->flags & option; if (flags == 0) - return FALSE; + return false; if ((flags != pinyin->flags) && ((pinyin->flags & PINYIN_CORRECT_ALL) != 0)) - return FALSE; + return false; } - return TRUE; + return true; } static int py_cmp (const void *p1, const void *p2) { - const gchar *str = (const gchar *) p1; + const char *str = (const char *) p1; const Pinyin *py = (const Pinyin *) p2; return std::strcmp (str, py->text); } +// TODO(hsumita): Replace "int len" to "size_t len" static const Pinyin * -is_pinyin (const gchar *p, - const gchar *end, - gint len, - guint option) +is_pinyin (const char *p, + const char *end, + int len, + unsigned int option) { - gchar buf[8]; + char buf[8]; const Pinyin *result; if (G_UNLIKELY (len > 6)) @@ -86,8 +87,9 @@ is_pinyin (const gchar *p, for (; len > 0; len --) { buf[len] = 0; + result = (const Pinyin *) std::bsearch (buf, pinyin_table, G_N_ELEMENTS (pinyin_table), - sizeof (Pinyin), py_cmp); + sizeof (Pinyin), py_cmp); if (G_UNLIKELY (check_flags (result, option))) { return result; } @@ -120,19 +122,18 @@ need_resplit(const Pinyin *p1, sizeof (special_table[0]), sp_cmp); } -guint +size_t PinyinParser::parse (const String &pinyin, - gint len, - guint option, + size_t len, + unsigned int option, PinyinArray &result, - guint max) + size_t max) { - - const gchar *p; - const gchar *end; + const char *p; + const char *end; const Pinyin *py; const Pinyin *prev_py; - gchar prev_c; + char prev_c; result.clear (); @@ -214,22 +215,22 @@ PinyinParser::parse (const String &pinyin, if (G_UNLIKELY (py == NULL)) break; - result.append (py, p - (const gchar *) pinyin, py->len); + result.append (py, p - (const char *) pinyin, py->len); p += py->len; prev_c = py->text[py->len - 1]; prev_py = py; } - if (G_UNLIKELY (p == (const gchar *)pinyin)) + if (G_UNLIKELY (p == (const char *)pinyin)) return 0; #if 0 if (G_UNLIKELY (*(p - 1) == '\'')) p --; #endif - return p - (const gchar *)pinyin; + return p - (const char *)pinyin; } -static const gchar * const +static const char * const id_map[] = { "", "b", "c", "ch", "d", "f", "g", "h", @@ -248,10 +249,10 @@ id_map[] = { }; const Pinyin * -PinyinParser::isPinyin (gint sheng, gint yun, guint option) +PinyinParser::isPinyin (int sheng, int yun, unsigned int option) { const Pinyin *result; - gchar buf[16]; + char buf[16]; std::strcpy (buf, id_map[sheng]); @@ -289,7 +290,7 @@ bopomofo_cmp (const void *p1, const void *p2) return std::wcscmp (s1, s2->bopomofo); } -gboolean +bool PinyinParser::isBopomofoToneChar (const wchar_t ch) { return ch == bopomofo_char[BOPOMOFO_TONE_2] @@ -298,18 +299,18 @@ PinyinParser::isBopomofoToneChar (const wchar_t ch) || ch == bopomofo_char[BOPOMOFO_TONE_5]; } -guint +size_t PinyinParser::parseBopomofo (const std::wstring &bopomofo, - gint len, - guint option, + size_t len, + unsigned int option, PinyinArray &result, - guint max) + size_t max) { std::wstring::const_iterator bpmf = bopomofo.begin(); const std::wstring::const_iterator end = bpmf + len; const Pinyin **bs_res; wchar_t buf[MAX_BOPOMOFO_LEN + 1]; - guint i, j; + size_t i, j; result.clear (); @@ -321,7 +322,7 @@ PinyinParser::parseBopomofo (const std::wstring &bopomofo, if (bpmf + i > end) continue; - for (j = 0; j < i; j++){ + for (j = 0; j < i; j++) { wchar_t key = *(bpmf + j); if (j == i - 1 && isBopomofoToneChar (key)) { diff --git a/src/PyZyPinyinParser.h b/src/PyZyPinyinParser.h index 31054f7..18bc961 100644 --- a/src/PyZyPinyinParser.h +++ b/src/PyZyPinyinParser.h @@ -22,7 +22,6 @@ #ifndef __PYZY_PINYIN_PARSER_H_ #define __PYZY_PINYIN_PARSER_H_ -#include <glib.h> #include "PyZyString.h" #include "PyZyPinyinArray.h" @@ -30,18 +29,18 @@ namespace PyZy { class PinyinParser { public: - static guint parse (const String &pinyin, // pinyin string - gint len, // length of pinyin string - guint option, // option - PinyinArray &result, // store pinyin in result - guint max); // max length of the result - static const Pinyin * isPinyin (gint sheng, gint yun, guint option); - static guint parseBopomofo (const std::wstring &bopomofo, - gint len, - guint option, - PinyinArray &result, - guint max); - static gboolean isBopomofoToneChar (const wchar_t ch); + static size_t parse (const String &pinyin, // pinyin string + size_t len, // length of pinyin string + unsigned int option, // option + PinyinArray &result, // store pinyin in result + size_t max); // max length of the result + static const Pinyin * isPinyin (int sheng, int yun, unsigned int option); + static size_t parseBopomofo (const std::wstring &bopomofo, + size_t len, + unsigned int option, + PinyinArray &result, + size_t max); + static bool isBopomofoToneChar (const wchar_t ch); }; diff --git a/src/PyZySimpTradConverter.cc b/src/PyZySimpTradConverter.cc index 3627b56..35bbec8 100644 --- a/src/PyZySimpTradConverter.cc +++ b/src/PyZySimpTradConverter.cc @@ -54,10 +54,10 @@ public: opencc_close(m_od); } - void convert (const gchar *in, String &out) + void convert (const char *in, String &out) { - glong n_char; - gunichar *in_ucs4 = g_utf8_to_ucs4_fast (in, -1, &n_char); + long n_char; + unichar *in_ucs4 = g_utf8_to_ucs4_fast (in, -1, &n_char); ucs4_t *pinbuf = (ucs4_t *)in_ucs4; size_t inbuf_left = n_char; @@ -68,7 +68,7 @@ public: if (retval == (size_t) -1) { /* append left chars in pinbuf */ g_warning ("opencc_convert return failed"); - out << (gunichar *) pinbuf; + out << (unichar *) pinbuf; break; } *poutbuf = L'\0'; @@ -78,11 +78,11 @@ public: } private: opencc_t m_od; - gunichar m_buffer[BUFFER_SIZE + 1]; + unichar m_buffer[BUFFER_SIZE + 1]; }; void -SimpTradConverter::simpToTrad (const gchar *in, String &out) +SimpTradConverter::simpToTrad (const char *in, String &out) { static opencc opencc; opencc.convert (in, out); @@ -90,7 +90,7 @@ SimpTradConverter::simpToTrad (const gchar *in, String &out) #else -static gint _xcmp (const gchar *p1, const gchar *p2, const gchar *str) +static int _xcmp (const char *p1, const char *p2, const char *str) { for (;;) { // both reach end @@ -112,10 +112,10 @@ static gint _xcmp (const gchar *p1, const gchar *p2, const gchar *str) }; } -static gint _cmp (gconstpointer p1, gconstpointer p2) +static int _cmp (const void * p1, const void * p2) { - const gchar **pp = (const gchar **) p1; - const gchar **s2 = (const gchar **) p2; + const char **pp = (const char **) p1; + const char **s2 = (const char **) p2; return _xcmp (pp[0], pp[1], s2[0]); } @@ -123,12 +123,12 @@ static gint _cmp (gconstpointer p1, gconstpointer p2) #include "PyZySimpTradConverterTable.h" void -SimpTradConverter::simpToTrad (const gchar *in, String &out) +SimpTradConverter::simpToTrad (const char *in, String &out) { - const gchar *pend; - const gchar *pp[2]; - glong len; - glong begin; + const char *pend; + const char *pp[2]; + size_t len; + size_t begin; if (!g_utf8_validate (in, -1 , NULL)) { g_warning ("\%s\" is not an utf8 string!", in); @@ -141,12 +141,12 @@ SimpTradConverter::simpToTrad (const gchar *in, String &out) pp[0] = in; while (pp[0] != pend) { - glong slen = std::min (len - begin, (glong) SIMP_TO_TRAD_MAX_LEN); // the length of sub string in character + size_t slen = std::min (len - begin, static_cast<size_t>(SIMP_TO_TRAD_MAX_LEN)); // the length of sub string in character pp[1] = g_utf8_offset_to_pointer (pp[0], slen); // the end of sub string for (;;) { - const gchar **result; - result = (const gchar **) std::bsearch (pp, simp_to_trad, + const char **result; + result = (const char **) std::bsearch (pp, simp_to_trad, G_N_ELEMENTS (simp_to_trad), sizeof (simp_to_trad[0]), _cmp); diff --git a/src/PyZySimpTradConverter.h b/src/PyZySimpTradConverter.h index fec8083..3c777e3 100644 --- a/src/PyZySimpTradConverter.h +++ b/src/PyZySimpTradConverter.h @@ -22,15 +22,13 @@ #ifndef __PYZY_SIMP_TRAD_CONVERTER_H_ #define __PYZY_SIMP_TRAD_CONVERTER_H_ -#include <glib.h> - namespace PyZy { class String; class SimpTradConverter { public: - static void simpToTrad (const gchar *in, String &out); + static void simpToTrad (const char *in, String &out); }; }; // namespace PyZy diff --git a/src/PyZySimpTradConverterTable.h b/src/PyZySimpTradConverterTable.h index ce20f8f..202c9bd 100644 --- a/src/PyZySimpTradConverterTable.h +++ b/src/PyZySimpTradConverterTable.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ -static const gchar *simp_to_trad[][2] = { +static const char *simp_to_trad[][2] = { { "〇余", "〇餘" }, { "〇只", "〇隻" }, { "一个准", "一個準" }, diff --git a/src/PyZySpecialPhrase.h b/src/PyZySpecialPhrase.h index 371baca..d113cee 100644 --- a/src/PyZySpecialPhrase.h +++ b/src/PyZySpecialPhrase.h @@ -23,16 +23,15 @@ #define __PYZY_SPECIAL_PHRASE_H_ #include <string> -#include <glib.h> namespace PyZy { class SpecialPhrase { public: - SpecialPhrase (guint pos) : m_position (pos) { } + SpecialPhrase (size_t pos) : m_position (pos) { } virtual ~SpecialPhrase (void) { } - guint position (void) const + size_t position (void) const { return m_position; } @@ -40,7 +39,7 @@ public: virtual std::string text (void) = 0; private: - guint m_position; + size_t m_position; }; }; // namespace PyZy diff --git a/src/PyZySpecialPhraseTable.cc b/src/PyZySpecialPhraseTable.cc index dca78d2..f9f155a 100644 --- a/src/PyZySpecialPhraseTable.cc +++ b/src/PyZySpecialPhraseTable.cc @@ -30,7 +30,7 @@ SpecialPhraseTable SpecialPhraseTable::m_instance; class StaticSpecialPhrase : public SpecialPhrase { public: - StaticSpecialPhrase (const std::string &text, guint pos) : + StaticSpecialPhrase (const std::string &text, size_t pos) : SpecialPhrase (pos), m_text (text) { } ~StaticSpecialPhrase (void) { } @@ -42,7 +42,7 @@ private: SpecialPhraseTable::SpecialPhraseTable (void) { - gchar * path = g_build_filename (g_get_user_config_dir (), + char * path = g_build_filename (g_get_user_config_dir (), "ibus", "pinyin", "phrases.txt", NULL); load ("phrases.txt") || @@ -51,7 +51,7 @@ SpecialPhraseTable::SpecialPhraseTable (void) g_free (path); } -gboolean +bool SpecialPhraseTable::lookup (const std::string &command, std::vector<std::string> &result) { @@ -65,14 +65,14 @@ SpecialPhraseTable::lookup (const std::string &command, return result.size () > 0; } -gboolean -SpecialPhraseTable::load (const gchar *file) +bool +SpecialPhraseTable::load (const char *file) { m_map.clear (); std::ifstream in (file); if (in.fail ()) - return FALSE; + return false; std::string line; while (!in.eof ()) { @@ -97,7 +97,7 @@ SpecialPhraseTable::load (const gchar *file) m_map.insert (Map::value_type (command, phrase)); } } - return TRUE; + return true; } }; // namespace PyZy diff --git a/src/PyZySpecialPhraseTable.h b/src/PyZySpecialPhraseTable.h index f28cfd3..61feb54 100644 --- a/src/PyZySpecialPhraseTable.h +++ b/src/PyZySpecialPhraseTable.h @@ -38,10 +38,10 @@ private: SpecialPhraseTable (void); public: - gboolean lookup (const std::string &command, std::vector<std::string> &result); + bool lookup (const std::string &command, std::vector<std::string> &result); private: - gboolean load (const gchar *file); + bool load (const char *file); public: static SpecialPhraseTable & instance (void) { return m_instance; } diff --git a/src/PyZyString.h b/src/PyZyString.h index aba26ae..f4ae4a7 100644 --- a/src/PyZyString.h +++ b/src/PyZyString.h @@ -25,19 +25,20 @@ #include <glib.h> #include <stdarg.h> #include <string> +#include "PyZyUtil.h" namespace PyZy { class String : public std::string { public: String () : std::string () { } - String (const gchar *str) : std::string (str) { } + String (const char *str) : std::string (str) { } String (const std::string &str) : std::string (str) { } - String (gint len) : std::string () { reserve (len); } + String (size_t len) : std::string () { reserve (len); } - String & printf (const gchar *fmt, ...) + String & printf (const char *fmt, ...) { - gchar *str; + char *str; va_list args; va_start (args, fmt); @@ -49,9 +50,9 @@ public: return *this; } - String & appendPrintf (const gchar *fmt, ...) + String & appendPrintf (const char *fmt, ...) { - gchar *str; + char *str; va_list args; va_start (args, fmt); @@ -64,29 +65,29 @@ public: return *this; } - String & appendUnichar (gunichar ch) + String & appendUnichar (unichar ch) { - gchar str[12]; - gint len; + char str[12]; + size_t len; len = g_unichar_to_utf8 (ch, str); str[len] = 0; append (str); return *this; } - String & insert (gint i, gchar ch) + String & insert (size_t i, char ch) { std::string::insert (i, 1, ch); return *this; } - String & truncate (guint len) + String & truncate (size_t len) { erase(len); return *this; } - String & replace (const gchar *pattern, const gchar *str) + String & replace (const char *pattern, const char *str) { String result; String::size_type pos = 0; @@ -104,36 +105,41 @@ public: return *this; } - gsize utf8Length (void) const + size_t utf8Length (void) const { return g_utf8_strlen (c_str(), -1); } - String & operator<< (gint i) + String & operator<< (int i) { return appendPrintf ("%d", i); } - String & operator<< (guint i) + String & operator<< (size_t i) + { + return appendPrintf("%zd", i); + } + + String & operator<< (unsigned int i) { return appendPrintf ("%u", i); } - String & operator<< (const gchar ch) + String & operator<< (const char ch) { append (1, ch); return *this; } - String & operator<< (const gchar *str) + String & operator<< (const char *str) { append (str); return *this; } - String & operator<< (const gunichar *wstr) + String & operator<< (const unichar *wstr) { - gchar *str; + char *str; GError *error; str = g_ucs4_to_utf8 (wstr, -1, NULL, NULL, &error); if (str == NULL) { @@ -147,7 +153,7 @@ public: return *this; } - gchar operator[] (gint i) + char operator[] (size_t i) { return std::string::operator[] (i); } @@ -159,21 +165,21 @@ public: String & operator<< (const String &str) { - return operator<< ((const gchar *)str); + return operator<< ((const char *)str); } - String & operator= (const gchar * str) + String & operator= (const char * str) { assign (str); return *this; } - operator const gchar *(void) const + operator const char *(void) const { return this->c_str (); } - operator gboolean (void) const + operator bool (void) const { return ! empty (); } diff --git a/src/PyZyTest.cc b/src/PyZyTest.cc index 0c6d27f..d226185 100644 --- a/src/PyZyTest.cc +++ b/src/PyZyTest.cc @@ -73,10 +73,10 @@ public: void lookupTableChanged (const InputContext *context) { ++m_lookup_table; } string commitedText () { return m_commited_text; } - guint commitTextCount () { return m_commit_text; } - guint preeditTextCount () { return m_preedit_text; } - guint auxiliaryTextCount () { return m_auxiliary_text; } - guint lookupTableCount () { return m_lookup_table; } + unsigned int commitTextCount () { return m_commit_text; } + unsigned int preeditTextCount () { return m_preedit_text; } + unsigned int auxiliaryTextCount () { return m_auxiliary_text; } + unsigned int lookupTableCount () { return m_lookup_table; } void clear () { m_commited_text.clear (); @@ -87,14 +87,14 @@ public: } private: string m_commited_text; - guint m_commit_text; - guint m_preedit_text; - guint m_auxiliary_text; - guint m_lookup_table; + unsigned int m_commit_text; + unsigned int m_preedit_text; + unsigned int m_auxiliary_text; + unsigned int m_lookup_table; }; void insertKeys (PhoneticContext &context, const string &keys) { - for (guint i = 0; i < keys.size (); ++i) { + for (size_t i = 0; i < keys.size (); ++i) { context.insert (keys[i]); } } diff --git a/src/PyZyTypes.h b/src/PyZyTypes.h index b8929af..b92da14 100644 --- a/src/PyZyTypes.h +++ b/src/PyZyTypes.h @@ -22,8 +22,6 @@ #ifndef __PYZY_TYPES_H_ #define __PYZY_TYPES_H_ -#include <glib.h> - namespace PyZy { #define PINYIN_ID_VOID (-1) @@ -127,16 +125,16 @@ namespace PyZy { #define PINYIN_FUZZY_ALL (0x1ffffe00) struct Pinyin { - const gchar *text; + const char *text; const wchar_t *bopomofo; - const gchar *sheng; - const gchar *yun; + const char *sheng; + const char *yun; struct { - guint8 sheng; - guint8 yun; + unsigned char sheng; + unsigned char yun; } pinyin_id[3]; - const guint len; - const guint flags; + const size_t len; + const unsigned int flags; }; #define MAX_UTF8_LEN 6 diff --git a/src/PyZyUtil.h b/src/PyZyUtil.h index 292fd85..d8d621d 100644 --- a/src/PyZyUtil.h +++ b/src/PyZyUtil.h @@ -35,7 +35,6 @@ #include <sys/utsname.h> #include <cstdlib> #include <string> -#include <glib/gtypes.h> #ifdef __GXX_EXPERIMENTAL_CXX0X__ # include <memory> @@ -54,14 +53,16 @@ namespace std { #endif // __GXX_EXPERIMENTAL_CXX0X__PYZY_ namespace PyZy { - +// for Unicode +typedef unsigned int unichar; + class UUID { public: UUID (void) { uuid_t u; #if defined(HAVE_UUID_CREATE) - gchar* uuid; + char *uuid; uuid_create (&u, 0); uuid_to_string (&u, &uuid, 0); g_strlcpy (m_uuid, uuid, sizeof(m_uuid)); @@ -72,13 +73,13 @@ public: #endif } - operator const gchar * (void) const + operator const char * (void) const { return m_uuid; } private: - gchar m_uuid[256]; + char m_uuid[256]; }; class Uname { @@ -88,14 +89,14 @@ public: uname (&m_buf); } - const gchar *hostname (void) const { return m_buf.nodename; } + const char *hostname (void) const { return m_buf.nodename; } private: struct utsname m_buf; }; class Hostname : public Uname { public: - operator const gchar * (void) const + operator const char * (void) const { return hostname (); } @@ -103,14 +104,14 @@ public: class Env : public std::string { public: - Env (const gchar *name) + Env (const char *name) { - gchar *str; + char *str; str = std::getenv (name); assign (str != NULL ? str : ""); } - operator const gchar *(void) const + operator const char *(void) const { return c_str(); } |