diff options
author | 2014-02-05 09:32:04 +0000 | |
---|---|---|
committer | 2014-02-05 09:32:04 +0000 | |
commit | 6e5dbdd5013258a33a3a9a3da0f0b74d3d9ed289 (patch) | |
tree | 569d530403da671652d1d907dc164733dfc099cc /java/src | |
parent | 6a16fa1f10ed5d429e5dbca51b552faee495ab2d (diff) | |
parent | d9c6b332090c90e4d4840e62fe3eb45c834b2e14 (diff) | |
download | latinime-6e5dbdd5013258a33a3a9a3da0f0b74d3d9ed289.tar.gz latinime-6e5dbdd5013258a33a3a9a3da0f0b74d3d9ed289.tar.xz latinime-6e5dbdd5013258a33a3a9a3da0f0b74d3d9ed289.zip |
Merge "Add null check to KeySpecParser"
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java | 17 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 292bf35cb..2a0dad678 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -120,6 +120,10 @@ public final class KeySpecParser { } public static String getLabel(final String keySpec) { + if (keySpec == null) { + // TODO: Throw {@link KeySpecParserError} once Key.keyLabel attribute becomes mandatory. + return null; + } if (hasIcon(keySpec)) { return null; } @@ -140,6 +144,10 @@ public final class KeySpecParser { } public static String getOutputText(final String keySpec) { + if (keySpec == null) { + // TODO: Throw {@link KeySpecParserError} once Key.keyLabel attribute becomes mandatory. + return null; + } final int labelEnd = indexOfLabelEnd(keySpec); if (hasCode(keySpec, labelEnd)) { return null; @@ -165,6 +173,10 @@ public final class KeySpecParser { } public static int getCode(final String keySpec, final KeyboardCodesSet codesSet) { + if (keySpec == null) { + // TODO: Throw {@link KeySpecParserError} once Key.keyLabel attribute becomes mandatory. + return CODE_UNSPECIFIED; + } final int labelEnd = indexOfLabelEnd(keySpec); if (hasCode(keySpec, labelEnd)) { checkDoubleLabelEnd(keySpec, labelEnd); @@ -187,6 +199,7 @@ public final class KeySpecParser { return (StringUtils.codePointCount(label) == 1) ? label.codePointAt(0) : CODE_OUTPUT_TEXT; } + // TODO: Make this method private once Key.code attribute is removed. public static int parseCode(final String text, final KeyboardCodesSet codesSet, final int defCode) { if (text == null) { @@ -202,6 +215,10 @@ public final class KeySpecParser { } public static int getIconId(final String keySpec) { + if (keySpec == null) { + // TODO: Throw {@link KeySpecParserError} once Key.keyLabel attribute becomes mandatory. + return KeyboardIconsSet.ICON_UNDEFINED; + } if (!hasIcon(keySpec)) { return KeyboardIconsSet.ICON_UNDEFINED; } diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java index d3bc0c2b2..0551e9e98 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java @@ -46,6 +46,9 @@ public final class MoreKeySpec { public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale, final KeyboardCodesSet codesSet) { + if (TextUtils.isEmpty(moreKeySpec)) { + throw new KeySpecParser.KeySpecParserError("Empty more key spec"); + } mLabel = StringUtils.toUpperCaseOfStringForLocale( KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale); final int code = StringUtils.toUpperCaseOfCodeForLocale( |