summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-03-11 10:49:17 +0800
committerPeng Wu <alexepico@gmail.com>2013-03-11 10:49:17 +0800
commit4c38e5cf9b9d48203f0d57432e8076c08653b134 (patch)
treefb644bdab20ee2b448894dddb6cf2232ea8731e4
parent6a448d5b60e5c9f7240d4149c3a81a0df439d275 (diff)
downloadibus-libpinyin-4c38e5cf9b9d48203f0d57432e8076c08653b134.tar.gz
ibus-libpinyin-4c38e5cf9b9d48203f0d57432e8076c08653b134.tar.xz
ibus-libpinyin-4c38e5cf9b9d48203f0d57432e8076c08653b134.zip
remove special phrases
-rw-r--r--po/POTFILES.in3
-rw-r--r--src/PYDynamicSpecialPhrase.cc314
-rw-r--r--src/PYDynamicSpecialPhrase.h60
-rw-r--r--src/PYSpecialPhrase.cc30
-rw-r--r--src/PYSpecialPhrase.h47
-rw-r--r--src/PYSpecialPhraseTable.cc103
-rw-r--r--src/PYSpecialPhraseTable.h58
7 files changed, 0 insertions, 615 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 08dc657..1abcd98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,5 @@
src/PYConfig.cc
src/PYPDoublePinyinEditor.cc
-src/PYDynamicSpecialPhrase.cc
src/PYEditor.cc
src/PYEngine.cc
src/PYExtEditor.cc
@@ -12,8 +11,6 @@ src/PYPPinyinEditor.cc
src/PYPPinyinEngine.cc
src/PYPinyinProperties.cc
src/PYSimpTradConverter.cc
-src/PYSpecialPhrase.cc
-src/PYSpecialPhraseTable.cc
src/PYEnglishEditor.cc
src/PYStrokeEditor.cc
setup/main2.py
diff --git a/src/PYDynamicSpecialPhrase.cc b/src/PYDynamicSpecialPhrase.cc
deleted file mode 100644
index 0e9597f..0000000
--- a/src/PYDynamicSpecialPhrase.cc
+++ /dev/null
@@ -1,314 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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 "PYDynamicSpecialPhrase.h"
-
-namespace PY {
-
-DynamicSpecialPhrase::~DynamicSpecialPhrase (void)
-{
-}
-
-std::string
-DynamicSpecialPhrase::text (void)
-{
- /* get the current time */
- std::time_t rawtime;
- std::time (&rawtime);
- m_time = *std::localtime (&rawtime);
-
- std::string result;
-
- size_t pos = 0;
- size_t pnext;
- gint s = 0;
- while (s != 2) {
- switch (s) {
- case 0: // expect "${"
- pnext = m_text.find ("${", pos);
- if (pnext == m_text.npos) {
- result += m_text.substr (pos);
- s = 2;
- }
- else {
- result += m_text.substr (pos, pnext - pos);
- pos = pnext + 2;
- s = 1;
- }
- break;
- case 1: // expect "}"
- pnext = m_text.find ("}", pos);
- if (pnext == m_text.npos) {
- result += "${";
- result += m_text.substr (pos);
- s = 2;
- }
- else {
- result += variable (m_text.substr(pos, pnext - pos));
- pos = pnext + 1;
- s = 0;
- }
- break;
- default: /* should not be reached */
- g_assert_not_reached ();
- }
- }
- return result;
-}
-
-inline const std::string
-DynamicSpecialPhrase::dec (gint d, const gchar *fmt)
-{
- gchar string [32];
- g_snprintf (string, sizeof (string), fmt, d);
- return string;
-}
-
-inline const std::string
-DynamicSpecialPhrase::year_cn (gboolean yy)
-{
- static const gchar * const digits[] = {
- "〇", "一", "二", "三", "四",
- "五", "六", "七", "八", "九"
- };
-
- gint year = m_time.tm_year + 1900;
- gint bit = 0;
- if (yy) {
- year %= 100;
- bit = 2;
- }
-
- std::string result;
- while (year != 0 || bit > 0) {
- result.insert(0, digits[year % 10]);
- year /= 10;
- bit -= 1;
- }
- return result;
-}
-
-inline const std::string
-DynamicSpecialPhrase::month_cn (void)
-{
- static const gchar * const month_num[] = {
- "一", "二", "三", "四", "五", "六", "七", "八",
- "九", "十", "十一", "十二"
- };
- return month_num[m_time.tm_mon];
-}
-
-inline const std::string
-DynamicSpecialPhrase::weekday_cn (void)
-{
- static const gchar * const week_num[] = {
- "日", "一", "二", "三", "四", "五", "六"
- };
- return week_num[m_time.tm_wday];
-}
-
-inline const std::string
-DynamicSpecialPhrase::hour_cn (guint i)
-{
- static const gchar * const hour_num[] = {
- "零", "一", "二", "三", "四",
- "五", "六", "七", "八", "九",
- "十", "十一", "十二", "十三", "十四",
- "十五", "十六", "十七", "十八", "十九",
- "二十", "二十一", "二十二", "二十三",
- };
- return hour_num[i];
-}
-
-inline const std::string
-DynamicSpecialPhrase::fullhour_cn (void)
-{
- return hour_cn (m_time.tm_hour);
-}
-
-inline const std::string
-DynamicSpecialPhrase::halfhour_cn (void)
-{
- return hour_cn (m_time.tm_hour % 12);
-}
-
-inline const std::string
-DynamicSpecialPhrase::day_cn (void)
-{
- static const gchar * const day_num[] = {
- "", "一", "二", "三", "四",
- "五", "六", "七", "八", "九",
- "", "十","二十", "三十"
- };
- guint day = m_time.tm_mday;
- return std::string (day_num[day / 10 + 10]) + day_num[day % 10];
-}
-
-inline const std::string
-DynamicSpecialPhrase::minsec_cn (guint i)
-{
- static const gchar * const num[] = {
- "", "一", "二", "三", "四",
- "五", "六", "七", "八", "九",
- "零", "十","二十", "三十", "四十"
- "五十", "六十"
- };
- return std::string (num[i / 10 + 10]) + num[i % 10];
-}
-
-static const char * numbers [2][10] = {
- {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖",},
- {"〇", "一", "二", "三", "四", "五", "六", "七", "八", "九",},
-};
-
-struct unit_t{
- const char * unit_zh_name; // Chinese Character
- const int digits; // Position in string.
- const bool persist; // Whether to force eating zero and force inserting into result string.
-};
-
-static unit_t units_simplified[] ={
- {"兆", 12, true},
- {"亿", 8, true},
- {"万", 4, true},
- {"千", 3, false},
- {"百", 2, false},
- {"十", 1, false},
- {"", 0, true},
-};
-
-static unit_t units_traditional[] ={
- {"兆", 12, true},
- {"亿", 8, true},
- {"万", 4, true},
- {"仟", 3, false},
- {"佰", 2, false},
- {"拾", 1, false},
- {"", 0, true},
-};
-
-
-const std::string
-DynamicSpecialPhrase::simplest_cn_number(gint64 num)
-{
- std::string result = "";
- if ( num == 0 )
- result = numbers[1][0];
- while (num > 0) {
- int remains = num % 10;
- num = num / 10;
- result = std::string ( numbers[1][remains] ) + result;
- }
-
- return result;
-}
-
-static inline const std::string
-translate_to_longform(gint64 num, const char * number[10], unit_t units[])
-{
- std::string result = "";
- int cur_pos = -1;
- bool eat_zero = false;
-
- while (num > 0) {
- int remains = num % 10;
- num = num / 10;
- cur_pos ++;
- std::string unit = "";
- int pos = cur_pos;
- size_t i = 6;
- while ( pos > 0 ) {
- for ( i = 0; i < 7; ++i) {
- pos = pos % units[i].digits;
- if ( pos == 0 )
- break;
- }
- }
-
- if ( units[i].persist ) {
- result = std::string (units[i].unit_zh_name) + result;
- eat_zero = true;
- }
-
- if ( remains == 0){
- if ( eat_zero ) continue;
-
- result = std::string (number[0]) + result;
- eat_zero = true;
- continue;
- }else{
- eat_zero = false;
- }
-
- if (num == 0 && remains == 1 && i == 5)
- result = std::string (units[i].unit_zh_name) + result;
- else if (units[i].persist)
- result = std::string (number[remains]) + result;
- else
- result = std::string (number[remains]) + std::string (units[i].unit_zh_name) + result;
- }
-
- return result;
-}
-
-const std::string
-DynamicSpecialPhrase::simplified_number(gint64 num)
-{
- return translate_to_longform(num, numbers[1], units_simplified);
-}
-
-const std::string
-DynamicSpecialPhrase::traditional_number(gint64 num)
-{
- if ( 0 == num )
- return numbers[0][0];
- return translate_to_longform(num, numbers[0], units_traditional);
-}
-
-inline const std::string
-DynamicSpecialPhrase::variable (const std::string &name)
-{
- if (name == "year") return dec (m_time.tm_year + 1900);
- if (name == "year_yy") return dec ((m_time.tm_year + 1900) % 100, "%02d");
- if (name == "month") return dec (m_time.tm_mon + 1);
- if (name == "month_mm") return dec (m_time.tm_mon + 1, "%02d");
- if (name == "day") return dec (m_time.tm_mday);
- if (name == "day_dd") return dec (m_time.tm_mday, "%02d");
- if (name == "weekday") return dec (m_time.tm_wday + 1);
- if (name == "fullhour") return dec (m_time.tm_hour, "%02d");
- if (name == "falfhour") return dec (m_time.tm_hour % 12, "%02d");
- if (name == "ampm") return m_time.tm_hour < 12 ? "AM" : "PM";
- if (name == "minute") return dec (m_time.tm_min, "%02d");
- if (name == "second") return dec (m_time.tm_sec, "%02d");
- if (name == "year_cn") return year_cn ();
- if (name == "year_yy_cn") return year_cn (TRUE);
- if (name == "month_cn") return month_cn ();
- if (name == "day_cn") return day_cn ();
- if (name == "weekday_cn") return weekday_cn ();
- if (name == "fullhour_cn") return fullhour_cn ();
- if (name == "halfhour_cn") return halfhour_cn ();
- if (name == "ampm_cn") return m_time.tm_hour < 12 ? "上午" : "下午";
- if (name == "minute_cn") return minsec_cn (m_time.tm_min);
- if (name == "second_cn") return minsec_cn (m_time.tm_sec);
-
- return "${" + name + "}";
-}
-
-};
diff --git a/src/PYDynamicSpecialPhrase.h b/src/PYDynamicSpecialPhrase.h
deleted file mode 100644
index 6795fc9..0000000
--- a/src/PYDynamicSpecialPhrase.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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.
- */
-#ifndef __PY_DYNAMIC_SPECIAL_PHRASE_H_
-#define __PY_DYNAMIC_SPECIAL_PHRASE_H_
-
-#include <ctime>
-#include <string>
-#include <glib.h>
-#include "PYSpecialPhrase.h"
-
-namespace PY {
-
-class DynamicSpecialPhrase : public SpecialPhrase {
-public:
- DynamicSpecialPhrase (const std::string &text, guint pos) :
- SpecialPhrase (pos), m_text (text) { }
- ~DynamicSpecialPhrase (void);
-
- std::string text (void);
- const std::string dec (gint d, const gchar *fmt = "%d");
- const std::string year_cn (gboolean yy = FALSE);
- const std::string month_cn (void);
- const std::string weekday_cn (void);
- const std::string hour_cn (guint i);
- const std::string fullhour_cn (void);
- const std::string halfhour_cn (void);
- const std::string day_cn (void);
- const std::string minsec_cn (guint i);
- const std::string variable (const std::string &name);
-
- /* declaration function about Chinese Number. */
- const std::string simplest_cn_number(gint64 num);
- const std::string simplified_number(gint64 num);
- const std::string traditional_number(gint64 num);
-
-private:
- std::string m_text;
- std::tm m_time;
-};
-
-};
-#endif
diff --git a/src/PYSpecialPhrase.cc b/src/PYSpecialPhrase.cc
deleted file mode 100644
index b88146b..0000000
--- a/src/PYSpecialPhrase.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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 "PYSpecialPhrase.h"
-
-namespace PY {
-
-SpecialPhrase::~SpecialPhrase (void)
-{
-}
-
-};
-
diff --git a/src/PYSpecialPhrase.h b/src/PYSpecialPhrase.h
deleted file mode 100644
index 4f7b8d6..0000000
--- a/src/PYSpecialPhrase.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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.
- */
-#ifndef __PY_SPECIAL_PHRASE_H_
-#define __PY_SPECIAL_PHRASE_H_
-
-#include <string>
-#include <glib.h>
-
-namespace PY {
-
-class SpecialPhrase {
-public:
- SpecialPhrase (guint pos) : m_position (pos) { }
- virtual ~SpecialPhrase (void);
-
- guint position (void) const
- {
- return m_position;
- }
-
- virtual std::string text (void) = 0;
-
-private:
- guint m_position;
-};
-
-};
-
-#endif
diff --git a/src/PYSpecialPhraseTable.cc b/src/PYSpecialPhraseTable.cc
deleted file mode 100644
index 545bfdc..0000000
--- a/src/PYSpecialPhraseTable.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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 "PYSpecialPhraseTable.h"
-#include <fstream>
-#include "PYDynamicSpecialPhrase.h"
-#include "PYSpecialPhrase.h"
-
-namespace PY {
-
-SpecialPhraseTable SpecialPhraseTable::m_instance;
-
-class StaticSpecialPhrase : public SpecialPhrase {
-public:
- StaticSpecialPhrase (const std::string &text, guint pos) :
- SpecialPhrase (pos), m_text (text) { }
- ~StaticSpecialPhrase (void) { }
-
- std::string text (void) { return m_text; }
-
-private:
- std::string m_text;
-};
-
-SpecialPhraseTable::SpecialPhraseTable (void)
-{
- gchar * path = g_build_filename (g_get_user_config_dir (),
- "ibus", "pinyin", "phrases.txt", NULL);
-
- load ("phrases.txt") ||
- load (path) ||
- load (PKGDATADIR G_DIR_SEPARATOR_S "phrases.txt");
- g_free (path);
-}
-
-gboolean
-SpecialPhraseTable::lookup (const std::string &command,
- std::vector<std::string> &result)
-{
- result.clear ();
-
- std::pair<Map::iterator, Map::iterator> range = m_map.equal_range (command);
- for (Map::iterator it = range.first; it != range.second; it ++) {
- result.push_back ((*it).second->text ());
- }
-
- return result.size () > 0;
-}
-
-gboolean
-SpecialPhraseTable::load (const gchar *file)
-{
- m_map.clear ();
-
- std::ifstream in (file);
- if (in.fail ())
- return FALSE;
-
- std::string line;
- while (!in.eof ()) {
- getline (in, line);
- if (line.size () == 0 || line[0] == ';')
- continue;
- size_t pos = line.find ('=');
- if (pos == line.npos)
- continue;
-
- std::string command = line.substr(0, pos);
- std::string value = line.substr(pos + 1);
- if (command.empty () || value.empty ())
- continue;
-
- if (value[0] != '#') {
- SpecialPhrasePtr phrase (new StaticSpecialPhrase (value, 0));
- m_map.insert (Map::value_type (command, phrase));
- }
- else if (value.size () > 1) {
- SpecialPhrasePtr phrase (new DynamicSpecialPhrase (value.substr (1), 0));
- m_map.insert (Map::value_type (command, phrase));
- }
- }
- return TRUE;
-}
-
-};
-
diff --git a/src/PYSpecialPhraseTable.h b/src/PYSpecialPhraseTable.h
deleted file mode 100644
index fe121e8..0000000
--- a/src/PYSpecialPhraseTable.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* vim:set et ts=4 sts=4:
- *
- * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
- *
- * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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.
- */
-#ifndef __PY_SPECIAL_PHRASE_TABLE_H_
-#define __PY_SPECIAL_PHRASE_TABLE_H_
-
-#include <map>
-#include <string>
-#include <vector>
-#include <glib.h>
-#include "PYUtil.h"
-
-namespace PY {
-
-class SpecialPhrase;
-typedef std::shared_ptr<SpecialPhrase> SpecialPhrasePtr;
-
-class SpecialPhraseTable {
-private:
- SpecialPhraseTable (void);
-
-public:
- gboolean lookup (const std::string &command, std::vector<std::string> &result);
-
-private:
- gboolean load (const gchar *file);
-
-public:
- static SpecialPhraseTable & instance (void) { return m_instance; }
-
-private:
- typedef std::multimap<std::string, SpecialPhrasePtr> Map;
- Map m_map;
-
-private:
- static SpecialPhraseTable m_instance;
-};
-
-};
-
-#endif