From bb48dfc2d26dfc4fe8bbdf85115f39186906cab2 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Wed, 9 Jun 2010 07:56:40 +0800 Subject: Use opencc --- src/Makefile.am | 2 ++ src/SimpTradConverter.cc | 31 ++++++++++++++++++++++++++++++- src/SimpTradConverter.h | 3 ++- 3 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 03a3d26..d7373dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,6 +117,7 @@ ibus_engine_pinyin_CXXFLAGS = \ @IBUS_CFLAGS@ \ @SQLITE_CFLAGS@ \ @BOOST_CPPFLAGS@ \ + @OPENCC_CFLAGS@ \ -DGETTEXT_PACKAGE=\"@GETTEXT_PACKAGE@\" \ -DPKGDATADIR=\"$(pkgdatadir)\" \ -DLIBEXECDIR=\"$(libexecdir)\" \ @@ -124,6 +125,7 @@ ibus_engine_pinyin_CXXFLAGS = \ ibus_engine_pinyin_LDADD = \ @IBUS_LIBS@ \ @SQLITE_LIBS@ \ + @OPENCC_LIBS@ \ $(NULL) if HAVE_LIBUUID diff --git a/src/SimpTradConverter.cc b/src/SimpTradConverter.cc index 96331c8..875d4b5 100644 --- a/src/SimpTradConverter.cc +++ b/src/SimpTradConverter.cc @@ -18,13 +18,26 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "SimpTradConverter.h" + #include #include #include -#include "SimpTradConverter.h" + +#ifdef HAVE_OPENCC +# include +#endif + +#include "String.h" namespace PY { +#ifndef HAVE_OPENCC #include "SimpTradConverterTable.h" +#endif static int _cmp (const void *p1, const void *p2) { @@ -34,6 +47,21 @@ static int _cmp (const void *p1, const void *p2) return std::wcscmp (s1, s2[0]); } +#ifdef HAVE_OPENCC +void +SimpTradConverter::simpToTrad (const gchar *in, String &out) +{ + static gunichar buf[64]; + gunichar *in_ucs4; + + in_ucs4 = g_utf8_to_ucs4_fast (in, -1, NULL); + + words_segmention ((wchar_t*)buf, (const wchar_t *)in_ucs4); + g_free (in_ucs4); + + out << buf; +} +#else void SimpTradConverter::simpToTrad (const gchar *in, String &out) { @@ -74,5 +102,6 @@ SimpTradConverter::simpToTrad (const gchar *in, String &out) g_free (in_ucs4); } +#endif } diff --git a/src/SimpTradConverter.h b/src/SimpTradConverter.h index ade9b3b..4cfa3a2 100644 --- a/src/SimpTradConverter.h +++ b/src/SimpTradConverter.h @@ -22,10 +22,11 @@ #define __SIMP_TRAD_CONVERTER_H_ #include -#include "String.h" namespace PY { +class String; + class SimpTradConverter { public: static void simpToTrad (const gchar *in, String &out); -- cgit