summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-05-28 15:23:41 +0800
committerPeng Wu <alexepico@gmail.com>2015-05-28 15:23:41 +0800
commit98f764e4acba396297a4776bb1d6293c5e3e5e9c (patch)
tree31a4e28063665796ae6ead95a7361187c569c93a
parent632da8adf04564a0ce928e8db3035f4fea79e734 (diff)
downloadlibpinyin-98f764e4acba396297a4776bb1d6293c5e3e5e9c.tar.gz
libpinyin-98f764e4acba396297a4776bb1d6293c5e3e5e9c.tar.xz
libpinyin-98f764e4acba396297a4776bb1d6293c5e3e5e9c.zip
update API
-rw-r--r--src/include/novel_types.h5
-rw-r--r--src/libpinyin.ver2
-rw-r--r--src/pinyin.cpp78
-rw-r--r--src/pinyin.h28
-rw-r--r--src/storage/table_info.h5
5 files changed, 69 insertions, 49 deletions
diff --git a/src/include/novel_types.h b/src/include/novel_types.h
index 8005ed0..7c545be 100644
--- a/src/include/novel_types.h
+++ b/src/include/novel_types.h
@@ -143,11 +143,6 @@ typedef GArray * CandidateConstraints;
typedef guint32 pinyin_option_t;
typedef enum {
- DEFAULT_TABLE,
- ADDON_TABLE,
-} TABLE_TARGET;
-
-typedef enum {
/* for default tables. */
RESERVED = 0,
GB_DICTIONARY = 1,
diff --git a/src/libpinyin.ver b/src/libpinyin.ver
index a7b5073..40cd154 100644
--- a/src/libpinyin.ver
+++ b/src/libpinyin.ver
@@ -6,6 +6,8 @@ LIBPINYIN {
pinyin_set_chewing_scheme;
pinyin_load_phrase_library;
pinyin_unload_phrase_library;
+ pinyin_load_addon_phrase_library;
+ pinyin_unload_addon_phrase_library;
pinyin_begin_add_phrases;
pinyin_iterator_add_phrase;
pinyin_end_add_phrases;
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 1ddc9ce..e7da8db 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -474,62 +474,60 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){
}
bool pinyin_load_phrase_library(pinyin_context_t * context,
- TABLE_TARGET target,
guint8 index){
if (!(index < PHRASE_INDEX_LIBRARY_COUNT))
return false;
- const pinyin_table_info_t * phrase_files = NULL;
- FacadePhraseIndex * phrase_index = NULL;
- const pinyin_table_info_t * table_info = NULL;
-
- if (DEFAULT_TABLE == target) {
- phrase_files = context->m_system_table_info.get_default_tables();
- phrase_index = context->m_phrase_index;
- table_info = phrase_files + index;
-
- /* Only SYSTEM_FILE or USER_FILE is allowed here. */
- assert(SYSTEM_FILE == table_info->m_file_type
- || USER_FILE == table_info->m_file_type);
- }
-
- if (ADDON_TABLE == target) {
- phrase_files = context->m_system_table_info.get_addon_tables();
- phrase_index = context->m_addon_phrase_index;
- table_info = phrase_files + index;
-
- /* Only DICTIONARY is allowed here. */
- assert(DICTIONARY == table_info->m_file_type);
- }
+ const pinyin_table_info_t * phrase_files =
+ context->m_system_table_info.get_default_tables();
+ FacadePhraseIndex * phrase_index = context->m_phrase_index;
+ const pinyin_table_info_t * table_info = phrase_files + index;
- _load_phrase_library(context->m_system_dir, context->m_user_dir,
- phrase_index, table_info);
+ /* Only SYSTEM_FILE or USER_FILE is allowed here. */
+ assert(SYSTEM_FILE == table_info->m_file_type
+ || USER_FILE == table_info->m_file_type);
- return false;
+ return _load_phrase_library(context->m_system_dir, context->m_user_dir,
+ phrase_index, table_info);
}
bool pinyin_unload_phrase_library(pinyin_context_t * context,
- TABLE_TARGET target,
guint8 index){
assert(index < PHRASE_INDEX_LIBRARY_COUNT);
/* default table. */
- if (DEFAULT_TABLE == target) {
- /* only GBK table can be unloaded. */
- if (GBK_DICTIONARY != index)
- return false;
+ /* only GBK table can be unloaded. */
+ if (GBK_DICTIONARY != index)
+ return false;
- context->m_phrase_index->unload(index);
- return true;
- }
+ context->m_phrase_index->unload(index);
+ return true;
+}
- /* addon table. */
- if (ADDON_TABLE == target) {
- context->m_addon_phrase_index->unload(index);
- return true;
- }
+bool pinyin_load_addon_phrase_library(pinyin_context_t * context,
+ guint8 index){
+ if (!(index < PHRASE_INDEX_LIBRARY_COUNT))
+ return false;
- return false;
+ const pinyin_table_info_t * phrase_files =
+ context->m_system_table_info.get_addon_tables();
+ FacadePhraseIndex * phrase_index = context->m_addon_phrase_index;
+ const pinyin_table_info_t * table_info = phrase_files + index;
+
+ /* Only DICTIONARY is allowed here. */
+ assert(DICTIONARY == table_info->m_file_type);
+
+ return _load_phrase_library(context->m_system_dir, context->m_user_dir,
+ phrase_index, table_info);
+}
+
+bool pinyin_unload_addon_phrase_library(pinyin_context_t * context,
+ guint8 index){
+ assert(index < PHRASE_INDEX_LIBRARY_COUNT);
+
+ /* addon table. */
+ context->m_addon_phrase_index->unload(index);
+ return true;
}
import_iterator_t * pinyin_begin_add_phrases(pinyin_context_t * context,
diff --git a/src/pinyin.h b/src/pinyin.h
index 12915ee..adb2bb8 100644
--- a/src/pinyin.h
+++ b/src/pinyin.h
@@ -64,7 +64,6 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir);
/**
* pinyin_load_phrase_library:
* @context: the pinyin context.
- * @target: the table target.
* @index: the phrase index to be loaded.
* @returns: whether the load succeeded.
*
@@ -72,13 +71,11 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir);
*
*/
bool pinyin_load_phrase_library(pinyin_context_t * context,
- TABLE_TARGET target,
guint8 index);
/**
* pinyin_unload_phrase_library:
* @context: the pinyin context.
- * @target: the table target.
* @index: the phrase index to be unloaded.
* @returns: whether the unload succeeded.
*
@@ -86,10 +83,33 @@ bool pinyin_load_phrase_library(pinyin_context_t * context,
*
*/
bool pinyin_unload_phrase_library(pinyin_context_t * context,
- TABLE_TARGET target,
guint8 index);
/**
+ * pinyin_load_addon_phrase_library:
+ * @context: the pinyin context.
+ * @index: the addon phrase index to be loaded.
+ * @returns: whether the load succeeded.
+ *
+ * Load the addon sub phrase library of the index.
+ *
+ */
+bool pinyin_load_addon_phrase_library(pinyin_context_t * context,
+ guint8 index);
+
+/**
+ * pinyin_unload_addon_phrase_library:
+ * @context: the pinyin context.
+ * @index: the addon phrase index to be unloaded.
+ * @returns: whether the unload succeeded.
+ *
+ * Unload the addon sub phrase library of the index.
+ *
+ */
+bool pinyin_unload_addon_phrase_library(pinyin_context_t * context,
+ guint8 index);
+
+/**
* pinyin_begin_add_phrases:
* @context: the pinyin context.
* @index: the phrase index to be imported.
diff --git a/src/storage/table_info.h b/src/storage/table_info.h
index 02245f1..467e754 100644
--- a/src/storage/table_info.h
+++ b/src/storage/table_info.h
@@ -33,6 +33,11 @@ typedef enum {
} TABLE_PHONETIC_TYPE;
typedef enum {
+ DEFAULT_TABLE,
+ ADDON_TABLE,
+} TABLE_TARGET;
+
+typedef enum {
NOT_USED, /* not used. */
SYSTEM_FILE, /* system phrase file. */
DICTIONARY, /* professional dictionary. */