diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/ZYTradSimpConverter.cc | 24 |
2 files changed, 4 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac index 58a019b..fb4b247 100644 --- a/configure.ac +++ b/configure.ac @@ -67,7 +67,7 @@ LIBZHUYIN_DATADIR=`$PKG_CONFIG --variable=pkgdatadir libzhuyin` AC_SUBST(LIBZHUYIN_DATADIR) # check opencc -PKG_CHECK_MODULES(OPENCC, [opencc], [enable_opencc=yes]) +PKG_CHECK_MODULES(OPENCC, [opencc >= 1.0.0], [enable_opencc=yes]) # check if ibus_config_get_values, which is available in ibus-1.3.99+ (git master) save_CFLAGS="$CFLAGS" diff --git a/src/ZYTradSimpConverter.cc b/src/ZYTradSimpConverter.cc index fceadb7..39f41d7 100644 --- a/src/ZYTradSimpConverter.cc +++ b/src/ZYTradSimpConverter.cc @@ -33,7 +33,6 @@ namespace ZY { class opencc { - static const int BUFFER_SIZE = 64; public: opencc (void) { @@ -48,30 +47,13 @@ public: void convert (const gchar *in, String &out) { - glong n_char; - gunichar *in_ucs4 = g_utf8_to_ucs4_fast (in, -1, &n_char); - - ucs4_t *pinbuf = (ucs4_t *)in_ucs4; - size_t inbuf_left = n_char; - while (inbuf_left != 0) { - ucs4_t *poutbuf = (ucs4_t *)m_buffer; - size_t outbuf_left = BUFFER_SIZE; - size_t retval = opencc_convert(m_cc, &pinbuf, &inbuf_left, &poutbuf, &outbuf_left); - if (retval == (size_t) -1) { - /* append left chars in pinbuf */ - g_warning ("opencc_convert return failed"); - out << (gunichar *) pinbuf; - break; - } - *poutbuf = L'\0'; - out << m_buffer; - } - g_free (in_ucs4); + char * converted = opencc_convert_utf8 (m_cc, in, -1); + out = converted; + opencc_convert_utf8_free (converted); } private: opencc_t m_cc; - gunichar m_buffer[BUFFER_SIZE + 1]; }; void |