summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-09-18 17:04:01 +0800
committerPeng Wu <alexepico@gmail.com>2014-09-18 17:04:01 +0800
commit44426ec675feb6fa5b003a612b03e80f226704ad (patch)
tree9b3f1f4349d33b5d38916a9462b934ab16e2491b
parent2a2ffe7d47726f389d331a9f0f694e094c7a4c14 (diff)
downloadibus-libzhuyin-44426ec675feb6fa5b003a612b03e80f226704ad.tar.gz
ibus-libzhuyin-44426ec675feb6fa5b003a612b03e80f226704ad.tar.xz
ibus-libzhuyin-44426ec675feb6fa5b003a612b03e80f226704ad.zip
import ZYSymbolLookup.cc
-rw-r--r--src/ZYSymbolLookup.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/ZYSymbolLookup.cc b/src/ZYSymbolLookup.cc
new file mode 100644
index 0000000..6faf703
--- /dev/null
+++ b/src/ZYSymbolLookup.cc
@@ -0,0 +1,90 @@
+/* vim:set et ts=4 sts=4:
+ *
+ * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus
+ *
+ * Copyright (c) 2014 Peng Wu <alexepico@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#include "ZYSymbolLookup.h"
+#include <stdio.h>
+
+
+gboolean
+SymbolLookup::loadFromFile(const char * filename)
+{
+ FILE * symbolfile = fopen (filename, "r");
+ if (NULL == symbolfile)
+ return FALSE;
+
+ char* linebuf = NULL; size_t size = 0; ssize_t read;
+ while ((read = getline (&linebuf, &size, symbolfile)) != -1) {
+ if (0 == strlen (linebuf))
+ continue;
+
+ if ( '\n' == linebuf[strlen (linebuf) - 1] ) {
+ linebuf[strlen (linebuf) - 1] = '\0';
+ }
+
+ gchar ** items = g_strsplit_set (linebuf, " =", 2);
+ guint len = g_strv_length (items);
+
+ if (0 == len)
+ continue;
+
+ String index = items[0];
+ /* for symbols.dat, copy display label from symbol. */
+ String symbol = index;
+ if (2 == len)
+ symbol = items[1];
+
+ /* just append. */
+ m_indexes.push_back (index);
+ m_symbols.push_back (symbol);
+
+ g_strfreev (items);
+ }
+
+ return TRUE;
+}
+
+String
+SymbolLookup::find (const String index)
+{
+ gboolean found = FALSE;
+
+ size_t i;
+ for(i = 0; i < m_indexes.size (); ++i) {
+ if (index == m_indexes[i]) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (found)
+ return m_symbols[i];
+
+ return "";
+}
+
+void
+SymbolLookup::dumpInfo ()
+{
+ size_t i;
+ for (i = 0; i < m_indexes.size (); ++i)
+ printf ("%s %s\n", m_indexes[i].c_str (), m_symbols[i].c_str ());
+}