diff options
author | Peng Wu <alexepico@gmail.com> | 2015-01-23 13:01:06 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2015-01-23 13:01:06 +0800 |
commit | 2445fbdb8f5f8300d3670249fbf6095a72c343b5 (patch) | |
tree | e6b9992c9e4fc9e29a9549afecf3a4e22ce13e69 | |
parent | 1bc034eaa38e56c9b9fc0151b9d56cfe3912af29 (diff) | |
download | ibus-libpinyin-2445fbdb8f5f8300d3670249fbf6095a72c343b5.tar.gz ibus-libpinyin-2445fbdb8f5f8300d3670249fbf6095a72c343b5.tar.xz ibus-libpinyin-2445fbdb8f5f8300d3670249fbf6095a72c343b5.zip |
write exportPinyinDictionary method
-rw-r--r-- | src/PYLibPinyin.cc | 33 | ||||
-rw-r--r-- | src/PYLibPinyin.h | 1 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc index 0090c0c..9931cac 100644 --- a/src/PYLibPinyin.cc +++ b/src/PYLibPinyin.cc @@ -254,6 +254,39 @@ LibPinyinBackEnd::importPinyinDictionary (const char * filename) } gboolean +LibPinyinBackEnd::exportPinyinDictionary (const char * filename) +{ + /* user phrase library should be already loaded here. */ + FILE * dictfile = fopen (filename, "w"); + if (NULL == dictfile) + return FALSE; + + export_iterator_t * iter = pinyin_begin_get_phrases + (m_pinyin_context, USER_DICTIONARY); + + if (NULL == iter) + return FALSE; + + /* use " " as the separator. */ + while (pinyin_iterator_has_next_phrase (iter)) { + gchar * phrase = NULL; gchar * pinyin = NULL; + gint count = -1; + + g_assert (pinyin_iterator_get_next_phrase (iter, &phrase, &pinyin, &count)); + + if (-1 == count) /* skip output the default count. */ + fprintf (dictfile, "%s %s\n", phrase, pinyin); + else /* output the count. */ + fprintf (dictfile, "%s %s %d\n", phrase, pinyin, count); + + g_free (phrase); g_free (pinyin); + } + + fclose (dictfile); + return TRUE; +} + +gboolean LibPinyinBackEnd::clearPinyinUserData (const char * target) { if (0 == strcmp ("all", target)) diff --git a/src/PYLibPinyin.h b/src/PYLibPinyin.h index 3e6a22e..c7511bc 100644 --- a/src/PYLibPinyin.h +++ b/src/PYLibPinyin.h @@ -51,6 +51,7 @@ public: void modified (void); gboolean importPinyinDictionary (const char * filename); + gboolean exportPinyinDictionary (const char * filename); gboolean clearPinyinUserData (const char * target); gboolean rememberUserInput (pinyin_instance_t * instance); |