aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorYuichiro Hanada <yhanada@google.com>2013-08-22 22:01:19 +0900
committerYuichiro Hanada <yhanada@google.com>2013-08-22 23:02:08 +0900
commitaa4168ee09e8bff6d4a27041566fe79f71cdbcf5 (patch)
treebf9447a0e4d7e2f54d77aa400fe37f43588091a7 /java
parente301085a70c9e5816fd98fb7d0fec3b2790b9359 (diff)
downloadlatinime-aa4168ee09e8bff6d4a27041566fe79f71cdbcf5.tar.gz
latinime-aa4168ee09e8bff6d4a27041566fe79f71cdbcf5.tar.xz
latinime-aa4168ee09e8bff6d4a27041566fe79f71cdbcf5.zip
Fix writePlacedNode.
Change-Id: I1d6b086f1d9f0dbd8d74f964e29ae62c533af978
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java9
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java12
2 files changed, 15 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
index 71c1d425c..40effb5e3 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java
@@ -108,7 +108,7 @@ public class BinaryDictEncoderUtils {
* like address lists do.
*/
static int getShortcutListSize(final ArrayList<WeightedString> shortcutList) {
- if (null == shortcutList) return 0;
+ if (null == shortcutList || shortcutList.isEmpty()) return 0;
int size = FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
for (final WeightedString shortcut : shortcutList) {
size += getShortcutSize(shortcut);
@@ -601,8 +601,9 @@ public class BinaryDictEncoderUtils {
private static byte makeCharGroupFlags(final CharGroup group, final int groupAddress,
final int childrenOffset, final FormatOptions formatOptions) {
return (byte) makeCharGroupFlags(group.mChars.length > 1, group.mFrequency >= 0,
- getByteSize(childrenOffset), group.mShortcutTargets != null, group.mBigrams != null,
- group.mIsNotAWord, group.mIsBlacklistEntry, formatOptions);
+ getByteSize(childrenOffset),
+ group.mShortcutTargets != null && !group.mShortcutTargets.isEmpty(),
+ group.mBigrams != null, group.mIsNotAWord, group.mIsBlacklistEntry, formatOptions);
}
/**
@@ -795,7 +796,7 @@ public class BinaryDictEncoderUtils {
groupAddress += shift;
// Write shortcuts
- if (null != group.mShortcutTargets) {
+ if (null != group.mShortcutTargets && !group.mShortcutTargets.isEmpty()) {
final int indexOfShortcutByteSize = index;
index += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
groupAddress += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
index 8d1b02713..494bbfcf2 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
@@ -255,18 +255,26 @@ public class Ver3DictDecoder implements DictDecoder {
childrenAddress += addressPointer;
}
addressPointer += BinaryDictIOUtils.getChildrenAddressSize(flags, options);
- ArrayList<WeightedString> shortcutTargets = null;
+ final ArrayList<WeightedString> shortcutTargets;
if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) {
+ // readShortcut will add shortcuts to shortcutTargets.
+ shortcutTargets = new ArrayList<WeightedString>();
addressPointer += PtNodeReader.readShortcut(mDictBuffer, shortcutTargets);
+ } else {
+ shortcutTargets = null;
}
- ArrayList<PendingAttribute> bigrams = null;
+
+ final ArrayList<PendingAttribute> bigrams;
if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) {
bigrams = new ArrayList<PendingAttribute>();
addressPointer += PtNodeReader.readBigrams(mDictBuffer, bigrams, addressPointer);
if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_GROUP) {
MakedictLog.d("too many bigrams in a group.");
}
+ } else {
+ bigrams = null;
}
+
return new CharGroupInfo(ptNodePos, addressPointer, flags, characters, frequency,
parentAddress, childrenAddress, shortcutTargets, bigrams);
}