summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-03-17 10:50:13 +0800
committerPeng Wu <alexepico@gmail.com>2015-03-17 10:50:13 +0800
commit26d2a5e8ae6bcccd329fc3e9c7a234519ac5ad88 (patch)
tree4b7e69762256e31ffa1e25f3f53d08eb751cab2c
parentcc55ba4f699fd64475f178c20d00f38dc7cf179b (diff)
downloadlibzhuyin-26d2a5e8ae6bcccd329fc3e9c7a234519ac5ad88.tar.gz
libzhuyin-26d2a5e8ae6bcccd329fc3e9c7a234519ac5ad88.tar.xz
libzhuyin-26d2a5e8ae6bcccd329fc3e9c7a234519ac5ad88.zip
fixes chewing simple parser
-rw-r--r--src/storage/pinyin_parser2.cpp24
-rw-r--r--src/storage/pinyin_parser2.h4
2 files changed, 19 insertions, 9 deletions
diff --git a/src/storage/pinyin_parser2.cpp b/src/storage/pinyin_parser2.cpp
index 9464de1..801531d 100644
--- a/src/storage/pinyin_parser2.cpp
+++ b/src/storage/pinyin_parser2.cpp
@@ -619,8 +619,12 @@ int ChewingSimpleParser2::parse(pinyin_option_t options,
int maximum_len = 0; int i;
/* probe the longest possible chewing string. */
for (i = 0; i < len; ++i) {
- if (!in_chewing_scheme(options, str[i], NULL))
+ gchar ** symbols = NULL;
+ if (!in_chewing_scheme(options, str[i], symbols)) {
+ g_strfreev(symbols);
break;
+ }
+ g_strfreev(symbols);
}
maximum_len = i;
@@ -683,16 +687,20 @@ bool ChewingSimpleParser2::set_scheme(ZhuyinScheme scheme) {
return false;
}
-
bool ChewingSimpleParser2::in_chewing_scheme(pinyin_option_t options,
const char key,
- const char ** symbol) const {
+ gchar ** & symbols) const {
+ symbols = NULL;
+ GPtrArray * array = g_ptr_array_new();
+
const gchar * chewing = NULL;
unsigned char tone = CHEWING_ZERO_TONE;
if (search_chewing_symbols(m_symbol_table, key, &chewing)) {
- if (symbol)
- *symbol = chewing;
+ g_ptr_array_add(array, g_strdup(chewing));
+ g_ptr_array_add(array, NULL);
+ /* must be freed by g_strfreev. */
+ symbols = (gchar **) g_ptr_array_free(array, FALSE);
return true;
}
@@ -700,8 +708,10 @@ bool ChewingSimpleParser2::in_chewing_scheme(pinyin_option_t options,
return false;
if (search_chewing_tones(m_tone_table, key, &tone)) {
- if (symbol)
- *symbol = chewing_tone_table[tone];
+ g_ptr_array_add(array, g_strdup(chewing_tone_table[tone]));
+ g_ptr_array_add(array, NULL);
+ /* must be freed by g_strfreev. */
+ symbols = (gchar **) g_ptr_array_free(array, FALSE);
return true;
}
diff --git a/src/storage/pinyin_parser2.h b/src/storage/pinyin_parser2.h
index 750f23c..72635c0 100644
--- a/src/storage/pinyin_parser2.h
+++ b/src/storage/pinyin_parser2.h
@@ -185,7 +185,7 @@ public:
*
*/
-class ChewingSimpleParser2 : public PhoneticParser2
+class ChewingSimpleParser2 : public ChewingParser2
{
/* internal options for chewing parsing. */
pinyin_option_t m_options;
@@ -209,7 +209,7 @@ public:
public:
bool set_scheme(ZhuyinScheme scheme);
- bool in_chewing_scheme(pinyin_option_t options, const char key, const char ** symbol) const;
+ virtual bool in_chewing_scheme(pinyin_option_t options, const char key, gchar ** & symbols) const;
};