summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-12-25 13:10:57 +0800
committerPeng Wu <alexepico@gmail.com>2014-12-25 13:10:57 +0800
commitb04d6793de65fa815737b5eb9a1db92a74bcf81f (patch)
treeaa71c13bb43662bd3d221d915828c732fe40a835
parent159039266a6b9530b9aad1362a8471aa80ea67fb (diff)
downloadibus-libpinyin-b04d6793de65fa815737b5eb9a1db92a74bcf81f.tar.gz
ibus-libpinyin-b04d6793de65fa815737b5eb9a1db92a74bcf81f.tar.xz
ibus-libpinyin-b04d6793de65fa815737b5eb9a1db92a74bcf81f.zip
use opencc 1.0
-rw-r--r--configure.ac2
-rw-r--r--src/PYSimpTradConverter.cc32
2 files changed, 8 insertions, 26 deletions
diff --git a/configure.ac b/configure.ac
index 3c6fd5c..6cbd8ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -112,7 +112,7 @@ AC_ARG_ENABLE(opencc,
)
if test x"$enable_opencc" = x"yes"; then
# check opencc
- PKG_CHECK_MODULES(OPENCC, [opencc], [
+ PKG_CHECK_MODULES(OPENCC, [opencc >= 1.0.0], [
AC_DEFINE(HAVE_OPENCC, 1, [Define if found opencc])
])
fi
diff --git a/src/PYSimpTradConverter.cc b/src/PYSimpTradConverter.cc
index 84cb30e..f92e452 100644
--- a/src/PYSimpTradConverter.cc
+++ b/src/PYSimpTradConverter.cc
@@ -40,44 +40,26 @@ namespace PY {
#ifdef HAVE_OPENCC
class opencc {
- static const int BUFFER_SIZE = 64;
public:
opencc (void)
{
- m_od = opencc_open (OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD);
- g_assert (m_od != NULL);
+ m_cc = opencc_open (OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD);
+ g_assert (m_cc != NULL);
}
~opencc (void)
{
- opencc_close(m_od);
+ opencc_close(m_cc);
}
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_od, &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_od;
- gunichar m_buffer[BUFFER_SIZE + 1];
+ opencc_t m_cc;
};
void