diff options
author | Peng Wu <alexepico@gmail.com> | 2016-07-21 15:58:21 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-07-21 15:58:21 +0800 |
commit | cc0fcf86673628e9883a18e191d47623a86f93e1 (patch) | |
tree | 0bfbe1dee2086ece605fbe65d73f4a5a329fe611 /src/storage | |
parent | bfe12876720e38a720169ef49a575e2f010a3579 (diff) | |
download | libpinyin-cc0fcf86673628e9883a18e191d47623a86f93e1.tar.gz libpinyin-cc0fcf86673628e9883a18e191d47623a86f93e1.tar.xz libpinyin-cc0fcf86673628e9883a18e191d47623a86f93e1.zip |
fixes fill_matrix function
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/phonetic_key_matrix.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp index c86d365..8f8bd4a 100644 --- a/src/storage/phonetic_key_matrix.cpp +++ b/src/storage/phonetic_key_matrix.cpp @@ -56,10 +56,18 @@ bool fill_matrix(PhoneticKeyMatrix * matrix, matrix->append(key_rest->m_raw_begin, *key, *key_rest); } - /* fill zero keys for "'". */ - ChewingKeyRest * next_key_rest = NULL; const ChewingKey zero_key; ChewingKeyRest zero_key_rest; + /* fill zero keys for the last key. */ + zero_key_rest.m_raw_begin = length - 1; + zero_key_rest.m_raw_end = length; + matrix->append(length - 1, zero_key, zero_key_rest); + + /* append the last key to key_rests. */ + g_array_append_val(key_rests, zero_key_rest); + + /* fill zero keys for "'". */ + ChewingKeyRest * next_key_rest = NULL; for (i = 0; i < key_rests->len - 1; ++i) { key_rest = &g_array_index(key_rests, ChewingKeyRest, i); next_key_rest = &g_array_index(key_rests, ChewingKeyRest, i + 1); @@ -72,10 +80,8 @@ bool fill_matrix(PhoneticKeyMatrix * matrix, } } - /* fill zero keys for the last key. */ - zero_key_rest.m_raw_begin = length - 1; - zero_key_rest.m_raw_end = length; - matrix->append(length - 1, zero_key, zero_key_rest); + /* remove the last key from key_rests. */ + g_array_set_size(key_rests, key_rests->len - 1); return true; } |