From: BYVoid Date: Mon, 5 Jul 2010 08:29:48 +0000 (+0800) Subject: Revert to OpenCC C language API X-Git-Tag: 1.3.10~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f46a3755384fb6dab200d42c059d3d9ec6ebbbf3;p=platform%2Fupstream%2Fibus-libpinyin.git Revert to OpenCC C language API --- diff --git a/src/SimpTradConverter.cc b/src/SimpTradConverter.cc index 1da4720..877e3c3 100644 --- a/src/SimpTradConverter.cc +++ b/src/SimpTradConverter.cc @@ -42,19 +42,39 @@ namespace PY { void SimpTradConverter::simpToTrad (const gchar *in, String &out) { - static opencc::converter conv (opencc::converter::CONFIG_SIMP_TO_TRAD); - static std::string inbuf, outbuf; - - inbuf = (const char *) in; - - if (conv == -1 || conv.convert (inbuf, outbuf) == -1) + const static int BUFFER_SIZE = 64; + static gunichar buf[BUFFER_SIZE + 1]; + gunichar *in_ucs4; + wchar_t * pinbuf, * poutbuf; + size_t inbuf_left, outbuf_left; + + in_ucs4 = g_utf8_to_ucs4_fast (in, -1, NULL); + pinbuf = (wchar_t *)in_ucs4; + poutbuf = (wchar_t *)buf; + inbuf_left = std::wcslen ((wchar_t *) pinbuf); + outbuf_left = BUFFER_SIZE; + + opencc_t od = opencc_open(OPENCC_DEFAULT_CONFIG_SIMP_TO_TRAD); + + size_t retv; + while ((retv = opencc_convert(od, &pinbuf, &inbuf_left, &poutbuf, &outbuf_left)) > 0) { - g_warning ("An error occurs in SimpTradConverter:"); - conv.perror (); - return; + if (retv == (size_t) -1) + { + g_warning ("SimpTradConverter:"); + opencc_perror("Opencc:"); + g_free (in_ucs4); + return; + } + + *poutbuf = L'\0'; + out << buf; + outbuf_left = BUFFER_SIZE; + poutbuf = (wchar_t *)buf; } - out << outbuf.c_str (); + opencc_close(od); + g_free (in_ucs4); } #else