summaryrefslogtreecommitdiffstats
path: root/src/pinyin.cpp
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-06-18 16:29:22 +0800
committerPeng Wu <alexepico@gmail.com>2012-06-18 16:29:22 +0800
commit9aaa1b504a366d5b13b138c44ed696306d4107b2 (patch)
tree6a9e844c8a35a361f1b9401389b267613183e50f /src/pinyin.cpp
parente347b7f9912592397accf7c51c0fa98335a70c86 (diff)
downloadlibpinyin-9aaa1b504a366d5b13b138c44ed696306d4107b2.tar.gz
libpinyin-9aaa1b504a366d5b13b138c44ed696306d4107b2.tar.xz
libpinyin-9aaa1b504a366d5b13b138c44ed696306d4107b2.zip
write get_dbin_filename
Diffstat (limited to 'src/pinyin.cpp')
-rw-r--r--src/pinyin.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index b191540..c3050a3 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -51,6 +51,14 @@ struct _pinyin_context_t{
gchar * m_phrase_indices[PHRASE_INDEX_LIBRARY_COUNT];
};
+static gchar * get_dbin_filename(const gchar * filename){
+ /* compute the delta bin file name. */
+ gchar * tmp = g_strdup(filename);
+ tmp[strlen(tmp) - 4] = '\0'; /* remove ".bin" */
+ gchar * dbinfilename = g_strdup_printf("%s.dbin", tmp);
+ g_free(tmp);
+ return dbinfilename;
+}
static bool check_format(const char * userdir){
gchar * filename = g_build_filename
@@ -81,11 +89,7 @@ static bool check_format(const char * userdir){
unlink(filename);
g_free(filename);
- /* compute the delta bin file name. */
- gchar * tmp = g_strdup(phrasefilename);
- tmp[strlen(tmp) - 4] = '\0'; /* remove ".bin" */
- gchar * dbinfilename = g_strdup_printf("%s.dbin", tmp);
- g_free(tmp);
+ gchar * dbinfilename = get_dbin_filename(phrasefilename);
/* remove dbin file. */
filename = g_build_filename(userdir, dbinfilename, NULL);
@@ -203,11 +207,7 @@ bool pinyin_load_phrase_library(pinyin_context_t * context,
g_free(chunkfilename);
context->m_phrase_index->load(index, chunk);
- /* compute the delta bin file name. */
- gchar * tmp = g_strdup(phrasefilename);
- tmp[strlen(tmp) - 4] = '\0'; /* remove ".bin" */
- gchar * dbinfilename = g_strdup_printf("%s.dbin", tmp);
- g_free(tmp);
+ gchar * dbinfilename = get_dbin_filename(phrasefilename);
chunkfilename = g_build_filename(context->m_user_dir,
dbinfilename, NULL);
@@ -283,12 +283,8 @@ bool pinyin_save(pinyin_context_t * context){
g_free(chunkfilename);
context->m_phrase_index->diff(i, chunk, log);
- /* compute the delta bin file name. */
- gchar * tmp = g_strdup(phrasefilename);
- tmp[strlen(tmp) - 4] = '\0'; /* remove ".bin" */
- gchar * dbinfilename = g_strdup_printf("%s.dbin", tmp);
+ gchar * dbinfilename = get_dbin_filename(phrasefilename);
gchar * tmpfilename = g_strdup_printf("%s.tmp", dbinfilename);
- g_free(tmp);
gchar * tmppathname = g_build_filename(context->m_user_dir,
tmpfilename, NULL);