Check the length of the word when add to FusionDictionary.

Change-Id: Id98d18e90a8b83b597507728b467f56888c8fd12
main
Yuichiro Hanada 2012-09-07 16:49:16 +09:00
parent 096f35ff4b
commit eae7b293e4
4 changed files with 18 additions and 2 deletions

View File

@ -41,7 +41,7 @@ public class BinaryDictionary extends Dictionary {
* It is necessary to keep it at this value because some languages e.g. German have
* really long words.
*/
public static final int MAX_WORD_LENGTH = 48;
public static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
public static final int MAX_WORDS = 18;
public static final int MAX_SPACES = 16;

View File

@ -128,6 +128,14 @@ public final class Constants {
}
}
public static class Dictionary {
public static final int MAX_WORD_LENGTH = 48;
private Dictionary() {
// This utility class is no publicly instantiable.
}
}
public static final int NOT_A_CODE = -1;
// See {@link KeyboardActionListener.Adapter#isInvalidCoordinate(int)}.

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@ -143,7 +144,7 @@ public class BinaryDictInputOutput {
// TODO: Make this value adaptative to content data, store it in the header, and
// use it in the reading code.
private static final int MAX_WORD_LENGTH = 48;
private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
private static final int MASK_GROUP_ADDRESS_TYPE = 0xC0;
private static final int FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = 0x00;

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.Constants;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -382,6 +384,11 @@ public class FusionDictionary implements Iterable<Word> {
final ArrayList<WeightedString> shortcutTargets,
final boolean isNotAWord, final boolean isBlacklistEntry) {
assert(frequency >= 0 && frequency <= 255);
if (word.length >= Constants.Dictionary.MAX_WORD_LENGTH) {
MakedictLog.w("Ignoring a word that is too long: word.length = " + word.length);
return;
}
Node currentNode = mRoot;
int charIndex = 0;