am e0952029
: Merge "Make KeySpecParser case sensitive again" into jb-dev
* commit 'e09520290fbcaff9a143e8c8bce80161b0e2c5a1': Make KeySpecParser case sensitive again
This commit is contained in:
commit
e03f6b3917
6 changed files with 135 additions and 137 deletions
|
@ -83,13 +83,13 @@ public class KeySpecParser {
|
|||
}
|
||||
|
||||
private static boolean hasIcon(String moreKeySpec) {
|
||||
return moreKeySpec.regionMatches(true, 0, PREFIX_ICON, 0, PREFIX_ICON.length());
|
||||
return moreKeySpec.startsWith(PREFIX_ICON);
|
||||
}
|
||||
|
||||
private static boolean hasCode(String moreKeySpec) {
|
||||
final int end = indexOfLabelEnd(moreKeySpec, 0);
|
||||
if (end > 0 && end + 1 < moreKeySpec.length() && moreKeySpec.regionMatches(
|
||||
true, end + 1, PREFIX_CODE, 0, PREFIX_CODE.length())) {
|
||||
if (end > 0 && end + 1 < moreKeySpec.length() && moreKeySpec.startsWith(
|
||||
PREFIX_CODE, end + 1)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -210,9 +210,9 @@ public class KeySpecParser {
|
|||
|
||||
public static int parseCode(String text, KeyboardCodesSet codesSet, int defCode) {
|
||||
if (text == null) return defCode;
|
||||
if (text.regionMatches(true, 0, PREFIX_CODE, 0, PREFIX_CODE.length())) {
|
||||
if (text.startsWith(PREFIX_CODE)) {
|
||||
return codesSet.getCode(text.substring(PREFIX_CODE.length()));
|
||||
} else if (text.regionMatches(true, 0, PREFIX_HEX, 0, PREFIX_HEX.length())) {
|
||||
} else if (text.startsWith(PREFIX_HEX)) {
|
||||
return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16);
|
||||
} else {
|
||||
return Integer.parseInt(text);
|
||||
|
@ -359,8 +359,7 @@ public class KeySpecParser {
|
|||
sb = null;
|
||||
for (int pos = 0; pos < size; pos++) {
|
||||
final char c = text.charAt(pos);
|
||||
if (text.regionMatches(true, pos, PREFIX_TEXT, 0, prefixLen)
|
||||
&& textsSet != null) {
|
||||
if (text.startsWith(PREFIX_TEXT, pos) && textsSet != null) {
|
||||
if (sb == null) {
|
||||
sb = new StringBuilder(text.substring(0, pos));
|
||||
}
|
||||
|
@ -392,8 +391,7 @@ public class KeySpecParser {
|
|||
for (int pos = start; pos < size; pos++) {
|
||||
final char c = text.charAt(pos);
|
||||
// Label name should be consisted of [a-zA-Z_0-9].
|
||||
if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')
|
||||
|| (c >= 'A' && c <= 'Z')) {
|
||||
if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) {
|
||||
continue;
|
||||
}
|
||||
return pos;
|
||||
|
@ -449,7 +447,7 @@ public class KeySpecParser {
|
|||
int value = defaultValue;
|
||||
for (int i = 0; i < moreKeys.length; i++) {
|
||||
final String moreKeySpec = moreKeys[i];
|
||||
if (moreKeySpec == null || !moreKeySpec.regionMatches(true, 0, key, 0, keyLen)) {
|
||||
if (moreKeySpec == null || !moreKeySpec.startsWith(key)) {
|
||||
continue;
|
||||
}
|
||||
moreKeys[i] = null;
|
||||
|
@ -473,7 +471,7 @@ public class KeySpecParser {
|
|||
boolean value = false;
|
||||
for (int i = 0; i < moreKeys.length; i++) {
|
||||
final String moreKeySpec = moreKeys[i];
|
||||
if (moreKeySpec == null || !moreKeySpec.equalsIgnoreCase(key)) {
|
||||
if (moreKeySpec == null || !moreKeySpec.equals(key)) {
|
||||
continue;
|
||||
}
|
||||
moreKeys[i] = null;
|
||||
|
|
|
@ -34,9 +34,8 @@ public class KeyboardIconsSet {
|
|||
private static final HashMap<Integer, Integer> ATTR_ID_TO_ICON_ID
|
||||
= new HashMap<Integer, Integer>();
|
||||
|
||||
// Lower case icon name to icon id map.
|
||||
private static final HashMap<String, Integer> sLowerCaseNameToIdsMap =
|
||||
new HashMap<String, Integer>();
|
||||
// Icon name to icon id map.
|
||||
private static final HashMap<String, Integer> sNameToIdsMap = new HashMap<String, Integer>();
|
||||
|
||||
private static final Object[] NAMES_AND_ATTR_IDS = {
|
||||
"undefined", ATTR_UNDEFINED,
|
||||
|
@ -70,7 +69,7 @@ public class KeyboardIconsSet {
|
|||
if (attrId != ATTR_UNDEFINED) {
|
||||
ATTR_ID_TO_ICON_ID.put(attrId, iconId);
|
||||
}
|
||||
sLowerCaseNameToIdsMap.put(name, iconId);
|
||||
sNameToIdsMap.put(name, iconId);
|
||||
ICON_NAMES[iconId] = name;
|
||||
iconId++;
|
||||
}
|
||||
|
@ -100,10 +99,7 @@ public class KeyboardIconsSet {
|
|||
}
|
||||
|
||||
static int getIconId(final String name) {
|
||||
Integer iconId = sLowerCaseNameToIdsMap.get(name);
|
||||
if (iconId == null) {
|
||||
iconId = sLowerCaseNameToIdsMap.get(name.toLowerCase());
|
||||
}
|
||||
Integer iconId = sNameToIdsMap.get(name);
|
||||
if (iconId != null) {
|
||||
return iconId;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public final class KeyboardTextsSet {
|
|||
// Language to texts map.
|
||||
private static final HashMap<String, String[]> sLocaleToTextsMap =
|
||||
new HashMap<String, String[]>();
|
||||
private static final HashMap<String, Integer> sLowerCaseNameToIdsMap =
|
||||
private static final HashMap<String, Integer> sNameToIdsMap =
|
||||
new HashMap<String, Integer>();
|
||||
|
||||
private String[] mTexts;
|
||||
|
@ -77,19 +77,11 @@ public final class KeyboardTextsSet {
|
|||
}
|
||||
|
||||
public String getText(final String name) {
|
||||
String lowerCaseName = null;
|
||||
String text = mResourceNameToTextsMap.get(name);
|
||||
if (text == null) {
|
||||
lowerCaseName = name.toLowerCase();
|
||||
text = mResourceNameToTextsMap.get(lowerCaseName);
|
||||
}
|
||||
if (text != null) {
|
||||
return text;
|
||||
}
|
||||
Integer id = sLowerCaseNameToIdsMap.get(name);
|
||||
if (id == null) {
|
||||
id = sLowerCaseNameToIdsMap.get(lowerCaseName); // lowerCaseName != null
|
||||
}
|
||||
final Integer id = sNameToIdsMap.get(name);
|
||||
if (id == null) throw new RuntimeException("Unknown label: " + name);
|
||||
text = (id < mTexts.length) ? mTexts[id] : null;
|
||||
return (text == null) ? LANGUAGE_DEFAULT[id] : text;
|
||||
|
@ -2484,7 +2476,7 @@ public final class KeyboardTextsSet {
|
|||
static {
|
||||
int id = 0;
|
||||
for (final String name : NAMES) {
|
||||
sLowerCaseNameToIdsMap.put(name, id++);
|
||||
sNameToIdsMap.put(name, id++);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
|
||||
|
|
|
@ -206,15 +206,11 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
public void testParseCsvResourceZero() {
|
||||
assertTextArray("Empty string",
|
||||
"!text/empty_string");
|
||||
assertTextArray("EMPTY STRING",
|
||||
"!TEXT/EMPTY_STRING");
|
||||
}
|
||||
|
||||
public void testParseCsvResourceSingle() {
|
||||
assertTextArray("Single char",
|
||||
"!text/single_char", "a");
|
||||
assertTextArray("SINGLE CHAR",
|
||||
"!TEXT/SINGLE_CHAR", "a");
|
||||
assertTextArray("Space",
|
||||
"!text/space", " ");
|
||||
assertTextArray("Single label",
|
||||
|
@ -232,8 +228,6 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
|
||||
assertTextArray("Escape and single char",
|
||||
"\\\\!text/single_char", "\\\\a");
|
||||
assertTextArray("Escape and SINGLE CHAR",
|
||||
"\\\\!TEXT/SINGLE_CHAR", "\\\\a");
|
||||
}
|
||||
|
||||
public void testParseCsvResourceSingleEscaped() {
|
||||
|
@ -266,8 +260,6 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
public void testParseCsvResourceMulti() {
|
||||
assertTextArray("Multiple chars",
|
||||
"!text/multiple_chars", "a", "b", "c");
|
||||
assertTextArray("MULTIPLE CHARS",
|
||||
"!TEXT/MULTIPLE_CHARS", "a", "b", "c");
|
||||
assertTextArray("Multiple chars surrounded by spaces",
|
||||
"!text/multiple_chars_surrounded_by_spaces",
|
||||
" a ", " b ", " c ");
|
||||
|
@ -301,8 +293,6 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
public void testParseMultipleResources() {
|
||||
assertTextArray("Literals and resources",
|
||||
"1,!text/multiple_chars,z", "1", "a", "b", "c", "z");
|
||||
assertTextArray("Literals and RESOURCES",
|
||||
"1,!TEXT/MULTIPLE_CHARS,z", "1", "a", "b", "c", "z");
|
||||
assertTextArray("Literals and resources and escape at end",
|
||||
"\\1,!text/multiple_chars,z\\", "\\1", "a", "b", "c", "z\\");
|
||||
assertTextArray("Multiple single resource chars and labels",
|
||||
|
@ -311,9 +301,6 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
assertTextArray("Multiple single resource chars and labels 2",
|
||||
"!text/single_char,!text/single_label,!text/escaped_comma_escape",
|
||||
"a", "abc", "a\\,\\");
|
||||
assertTextArray("Multiple single RESOURCE chars and LABELS 2",
|
||||
"!TEXT/SINGLE_CHAR,!TEXT/SINGLE_LABEL,!TEXT/ESCAPED_COMMA_ESCAPE",
|
||||
"a", "abc", "a\\,\\");
|
||||
assertTextArray("Multiple multiple resource chars and labels",
|
||||
"!text/multiple_chars,!text/multiple_labels,!text/multiple_chars_with_comma",
|
||||
"a", "b", "c", "abc", "def", "ghi", "a", "\\,", "c");
|
||||
|
@ -332,66 +319,88 @@ public class KeySpecParserCsvTests extends AndroidTestCase {
|
|||
"1,!text/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2");
|
||||
assertTextArray("Indirect2",
|
||||
"!text/indirect2_string", "a", "b", "c");
|
||||
|
||||
assertTextArray("INDIRECT",
|
||||
"!TEXT/INDIRECT_STRING", "a", "b", "c");
|
||||
assertTextArray("INDIRECT with literal",
|
||||
"1,!TEXT/INDIRECT_STRING_WITH_LITERAL,2", "1", "x", "a", "b", "c", "y", "2");
|
||||
assertTextArray("INDIRECT2",
|
||||
"!TEXT/INDIRECT2_STRING", "a", "b", "c");
|
||||
|
||||
assertTextArray("Upper indirect",
|
||||
"!text/upper_indirect_string", "a", "b", "c");
|
||||
assertTextArray("Upper indirect with literal",
|
||||
"1,!text/upper_indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2");
|
||||
assertTextArray("Upper indirect2",
|
||||
"!text/upper_indirect2_string", "a", "b", "c");
|
||||
|
||||
assertTextArray("UPPER INDIRECT",
|
||||
"!TEXT/upper_INDIRECT_STRING", "a", "b", "c");
|
||||
assertTextArray("Upper INDIRECT with literal",
|
||||
"1,!TEXT/upper_INDIRECT_STRING_WITH_LITERAL,2", "1", "x", "a", "b", "c", "y", "2");
|
||||
assertTextArray("Upper INDIRECT2",
|
||||
"!TEXT/upper_INDIRECT2_STRING", "a", "b", "c");
|
||||
}
|
||||
|
||||
public void testParseInfiniteIndirectReference() {
|
||||
assertError("Infinite indirection",
|
||||
"1,!text/infinite_indirection,2", "1", "infinite", "<infinite>", "loop", "2");
|
||||
assertError("INFINITE INDIRECTION",
|
||||
"1,!TEXT/INFINITE_INDIRECTION,2", "1", "infinite", "<infinite>", "loop", "2");
|
||||
|
||||
assertError("Upper infinite indirection",
|
||||
"1,!text/upper_infinite_indirection,2",
|
||||
"1", "infinite", "<infinite>", "loop", "2");
|
||||
assertError("Upper INFINITE INDIRECTION",
|
||||
"1,!TEXT/UPPER_INFINITE_INDIRECTION,2",
|
||||
"1", "infinite", "<infinite>", "loop", "2");
|
||||
}
|
||||
|
||||
public void testLabelReferece() {
|
||||
assertTextArray("Label time am", "!text/label_time_am", "AM");
|
||||
assertTextArray("LABEL TIME AM", "!TEXT/LABEL_TIME_AM", "AM");
|
||||
|
||||
assertTextArray("More keys for am pm", "!text/more_keys_for_am_pm",
|
||||
"!fixedColumnOrder!2", "!hasLabels!", "AM", "PM");
|
||||
assertTextArray("MORE KEYS FOR AM OM", "!TEXT/MORE_KEYS_FOR_AM_PM",
|
||||
"!fixedColumnOrder!2", "!hasLabels!", "AM", "PM");
|
||||
|
||||
assertTextArray("Settings as more key", "!text/settings_as_more_key",
|
||||
"!icon/settings_key|!code/key_settings");
|
||||
assertTextArray("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY",
|
||||
"!icon/settings_key|!code/key_settings");
|
||||
|
||||
assertTextArray("Indirect naviagte actions as more key",
|
||||
"!text/indirect_navigate_actions_as_more_key",
|
||||
"!fixedColumnOrder!2",
|
||||
"!hasLabels!", "Prev|!code/key_action_previous",
|
||||
"!hasLabels!", "Next|!code/key_action_next");
|
||||
}
|
||||
|
||||
public void testUselessUpperCaseSpecifier() {
|
||||
assertTextArray("EMPTY STRING",
|
||||
"!TEXT/EMPTY_STRING", "!TEXT/EMPTY_STRING");
|
||||
|
||||
assertTextArray("SINGLE CHAR",
|
||||
"!TEXT/SINGLE_CHAR", "!TEXT/SINGLE_CHAR");
|
||||
assertTextArray("Escape and SINGLE CHAR",
|
||||
"\\\\!TEXT/SINGLE_CHAR", "\\\\!TEXT/SINGLE_CHAR");
|
||||
|
||||
assertTextArray("MULTIPLE CHARS",
|
||||
"!TEXT/MULTIPLE_CHARS", "!TEXT/MULTIPLE_CHARS");
|
||||
|
||||
assertTextArray("Literals and RESOURCES",
|
||||
"1,!TEXT/MULTIPLE_CHARS,z", "1", "!TEXT/MULTIPLE_CHARS", "z");
|
||||
assertTextArray("Multiple single RESOURCE chars and LABELS 2",
|
||||
"!TEXT/SINGLE_CHAR,!TEXT/SINGLE_LABEL,!TEXT/ESCAPED_COMMA_ESCAPE",
|
||||
"!TEXT/SINGLE_CHAR", "!TEXT/SINGLE_LABEL", "!TEXT/ESCAPED_COMMA_ESCAPE");
|
||||
|
||||
assertTextArray("INDIRECT",
|
||||
"!TEXT/INDIRECT_STRING", "!TEXT/INDIRECT_STRING");
|
||||
assertTextArray("INDIRECT with literal",
|
||||
"1,!TEXT/INDIRECT_STRING_WITH_LITERAL,2",
|
||||
"1", "!TEXT/INDIRECT_STRING_WITH_LITERAL", "2");
|
||||
assertTextArray("INDIRECT2",
|
||||
"!TEXT/INDIRECT2_STRING", "!TEXT/INDIRECT2_STRING");
|
||||
|
||||
assertTextArray("Upper indirect",
|
||||
"!text/upper_indirect_string", "!TEXT/MULTIPLE_CHARS");
|
||||
assertTextArray("Upper indirect with literal",
|
||||
"1,!text/upper_indirect_string_with_literal,2",
|
||||
"1", "x", "!TEXT/MULTIPLE_CHARS", "y", "2");
|
||||
assertTextArray("Upper indirect2",
|
||||
"!text/upper_indirect2_string", "!TEXT/UPPER_INDIRECT_STRING");
|
||||
|
||||
assertTextArray("UPPER INDIRECT",
|
||||
"!TEXT/upper_INDIRECT_STRING", "!TEXT/upper_INDIRECT_STRING");
|
||||
assertTextArray("Upper INDIRECT with literal",
|
||||
"1,!TEXT/upper_INDIRECT_STRING_WITH_LITERAL,2",
|
||||
"1", "!TEXT/upper_INDIRECT_STRING_WITH_LITERAL", "2");
|
||||
assertTextArray("Upper INDIRECT2",
|
||||
"!TEXT/upper_INDIRECT2_STRING", "!TEXT/upper_INDIRECT2_STRING");
|
||||
|
||||
assertTextArray("INFINITE INDIRECTION",
|
||||
"1,!TEXT/INFINITE_INDIRECTION,2", "1", "!TEXT/INFINITE_INDIRECTION", "2");
|
||||
|
||||
assertTextArray("Upper infinite indirection",
|
||||
"1,!text/upper_infinite_indirection,2",
|
||||
"1", "infinite", "!TEXT/INFINITE_INDIRECTION", "loop", "2");
|
||||
assertTextArray("Upper INFINITE INDIRECTION",
|
||||
"1,!TEXT/UPPER_INFINITE_INDIRECTION,2",
|
||||
"1", "!TEXT/UPPER_INFINITE_INDIRECTION", "2");
|
||||
|
||||
assertTextArray("LABEL TIME AM", "!TEXT/LABEL_TIME_AM", "!TEXT/LABEL_TIME_AM");
|
||||
assertTextArray("MORE KEYS FOR AM OM", "!TEXT/MORE_KEYS_FOR_AM_PM",
|
||||
"!TEXT/MORE_KEYS_FOR_AM_PM");
|
||||
assertTextArray("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY",
|
||||
"!TEXT/SETTINGS_AS_MORE_KEY");
|
||||
assertTextArray("INDIRECT NAVIGATE ACTIONS AS MORE KEY",
|
||||
"!TEXT/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY",
|
||||
"!fixedColumnOrder!2",
|
||||
"!hasLabels!", "Prev|!code/key_action_previous",
|
||||
"!hasLabels!", "Next|!code/key_action_next");
|
||||
}
|
||||
"!TEXT/INDIRECT_NAVIGATE_ACTIONS_AS_MORE_KEY");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,8 +150,6 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
"|", null, ICON_UNDEFINED, '|');
|
||||
assertParser("Single letter with code", "a|" + CODE_SETTINGS,
|
||||
"a", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Single letter with CODE", "a|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a", null, ICON_UNDEFINED, mCodeSettings);
|
||||
}
|
||||
|
||||
public void testLabel() {
|
||||
|
@ -214,66 +212,39 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
"a|c", "d|f", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Label with code", "abc|" + CODE_SETTINGS,
|
||||
"abc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Label with CODE", "abc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"abc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParser("Escaped label with code", "a\\|c|" + CODE_SETTINGS,
|
||||
"a|c", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Escaped label with CODE", "a\\|c|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a|c", null, ICON_UNDEFINED, mCodeSettings);
|
||||
}
|
||||
|
||||
public void testIconAndCode() {
|
||||
assertParser("Icon with outputText", ICON_SETTINGS + "|abc",
|
||||
null, "abc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText", ICON_SETTINGS_UPPERCASE + "|abc",
|
||||
null, "abc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("Icon with outputText starts with bang", ICON_SETTINGS + "|!bc",
|
||||
null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText starts with bang", ICON_SETTINGS_UPPERCASE + "|!bc",
|
||||
null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("Icon with outputText contains bang", ICON_SETTINGS + "|a!c",
|
||||
null, "a!c", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText contains bang", ICON_SETTINGS_UPPERCASE + "|a!c",
|
||||
null, "a!c", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("Icon with escaped bang outputText", ICON_SETTINGS + "|\\!bc",
|
||||
null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with escaped bang outputText", ICON_SETTINGS_UPPERCASE + "|\\!bc",
|
||||
null, "!bc", mSettingsIconId, CODE_OUTPUT_TEXT);
|
||||
assertParser("Label starts with bang and code", "!bc|" + CODE_SETTINGS,
|
||||
"!bc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Label starts with bang and CODE", "!bc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"!bc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParser("Label contains bang and code", "a!c|" + CODE_SETTINGS,
|
||||
"a!c", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Label contains bang and CODE", "a!c|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a!c", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParser("Escaped bang label with code", "\\!bc|" + CODE_SETTINGS,
|
||||
"!bc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Escaped bang label with CODE", "\\!bc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"!bc", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS,
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
assertParserError("ICON with CODE", ICON_SETTINGS_UPPERCASE + "|" + CODE_SETTINGS_UPPERCASE,
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
}
|
||||
|
||||
public void testResourceReference() {
|
||||
assertParser("Settings as more key", "!text/settings_as_more_key",
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
assertParser("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY",
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
|
||||
assertParser("Action next as more key", "!text/label_next_key|!code/key_action_next",
|
||||
"Next", null, ICON_UNDEFINED, mCodeActionNext);
|
||||
assertParserError("ACTION NEXT AS MORE KEY", "!TEXT/LABEL_NEXT_KEY|!CODE/KEY_ACTION_NEXT",
|
||||
"Next", null, ICON_UNDEFINED, mCodeActionNext);
|
||||
|
||||
assertParser("Popular domain",
|
||||
"!text/keylabel_for_popular_domain|!text/keylabel_for_popular_domain ",
|
||||
".com", ".com ", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("POPULAR DOMAIN",
|
||||
"!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN|!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN ",
|
||||
".com", ".com ", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
}
|
||||
|
||||
public void testFormatError() {
|
||||
|
@ -283,20 +254,14 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
null, "a", ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||
assertParserError("Empty label with code", "|" + CODE_SETTINGS,
|
||||
null, null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Empty label with CODE", "|" + CODE_SETTINGS_UPPERCASE,
|
||||
null, null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Empty outputText with label", "a|",
|
||||
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||
assertParserError("Empty outputText with icon", ICON_SETTINGS + "|",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Empty outputText with ICON", ICON_SETTINGS_UPPERCASE + "|",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Empty icon and code", "|",
|
||||
null, null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||
assertParserError("Icon without code", ICON_SETTINGS,
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("ICON without code", ICON_SETTINGS_UPPERCASE,
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc",
|
||||
null, "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParserError("Non existing code", "abc|" + CODE_NON_EXISTING,
|
||||
|
@ -307,15 +272,56 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||
assertParserError("Multiple bar with label and code", "a|" + CODE_SETTINGS + "|c",
|
||||
"a", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Multiple bar with label and CODE", "a|" + CODE_SETTINGS_UPPERCASE + "|c",
|
||||
"a", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Multiple bar with icon and outputText", ICON_SETTINGS + "|b|c",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Multiple bar with ICON and outputText", ICON_SETTINGS_UPPERCASE + "|b|c",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Multiple bar with icon and code",
|
||||
ICON_SETTINGS + "|" + CODE_SETTINGS + "|c",
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
}
|
||||
|
||||
public void testUselessUpperCaseSpecifier() {
|
||||
assertParser("Single letter with CODE", "a|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Label with CODE", "abc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"abc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Escaped label with CODE", "a\\|c|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a|c", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText", ICON_SETTINGS_UPPERCASE + "|abc",
|
||||
"!ICON/SETTINGS_KEY", "abc", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText starts with bang", ICON_SETTINGS_UPPERCASE + "|!bc",
|
||||
"!ICON/SETTINGS_KEY", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with outputText contains bang", ICON_SETTINGS_UPPERCASE + "|a!c",
|
||||
"!ICON/SETTINGS_KEY", "a!c", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with escaped bang outputText", ICON_SETTINGS_UPPERCASE + "|\\!bc",
|
||||
"!ICON/SETTINGS_KEY", "!bc", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Label starts with bang and CODE", "!bc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"!bc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Label contains bang and CODE", "a!c|" + CODE_SETTINGS_UPPERCASE,
|
||||
"a!c", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("Escaped bang label with CODE", "\\!bc|" + CODE_SETTINGS_UPPERCASE,
|
||||
"!bc", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("ICON with CODE", ICON_SETTINGS_UPPERCASE + "|" + CODE_SETTINGS_UPPERCASE,
|
||||
"!ICON/SETTINGS_KEY", "!CODE/KEY_SETTINGS", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParser("SETTINGS AS MORE KEY", "!TEXT/SETTINGS_AS_MORE_KEY",
|
||||
"!TEXT/SETTINGS_AS_MORE_KEY", "!TEXT/SETTINGS_AS_MORE_KEY", ICON_UNDEFINED,
|
||||
CODE_OUTPUT_TEXT);
|
||||
assertParser("ACTION NEXT AS MORE KEY", "!TEXT/LABEL_NEXT_KEY|!CODE/KEY_ACTION_NEXT",
|
||||
"!TEXT/LABEL_NEXT_KEY", "!CODE/KEY_ACTION_NEXT", ICON_UNDEFINED,
|
||||
CODE_OUTPUT_TEXT);
|
||||
assertParser("POPULAR DOMAIN",
|
||||
"!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN|!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN ",
|
||||
"!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN", "!TEXT/KEYLABEL_FOR_POPULAR_DOMAIN ",
|
||||
ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParserError("Empty label with CODE", "|" + CODE_SETTINGS_UPPERCASE,
|
||||
null, null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Empty outputText with ICON", ICON_SETTINGS_UPPERCASE + "|",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParser("ICON without code", ICON_SETTINGS_UPPERCASE,
|
||||
"!ICON/SETTINGS_KEY", "!ICON/SETTINGS_KEY", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||
assertParserError("Multiple bar with label and CODE", "a|" + CODE_SETTINGS_UPPERCASE + "|c",
|
||||
"a", null, ICON_UNDEFINED, mCodeSettings);
|
||||
assertParserError("Multiple bar with ICON and outputText", ICON_SETTINGS_UPPERCASE + "|b|c",
|
||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||
assertParserError("Multiple bar with ICON and CODE",
|
||||
ICON_SETTINGS_UPPERCASE + "|" + CODE_SETTINGS_UPPERCASE + "|c",
|
||||
null, null, mSettingsIconId, mCodeSettings);
|
||||
|
@ -578,9 +584,10 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
assertGetBooleanValue("Has label", HAS_LABEL,
|
||||
new String[] { HAS_LABEL, "a", "b", "c" },
|
||||
new String[] { null, "a", "b", "c" }, true);
|
||||
// Upper case specification will not work.
|
||||
assertGetBooleanValue("HAS LABEL", HAS_LABEL,
|
||||
new String[] { HAS_LABEL.toUpperCase(), "a", "b", "c" },
|
||||
new String[] { null, "a", "b", "c" }, true);
|
||||
new String[] { "!HASLABEL!", "a", "b", "c" }, false);
|
||||
|
||||
assertGetBooleanValue("No has label", HAS_LABEL,
|
||||
new String[] { "a", "b", "c" },
|
||||
|
@ -589,16 +596,18 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" },
|
||||
new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" }, false);
|
||||
|
||||
// Upper case specification will not work.
|
||||
assertGetBooleanValue("Multiple has label", HAS_LABEL,
|
||||
new String[] {
|
||||
"a", HAS_LABEL.toUpperCase(), "b", "c", HAS_LABEL, "d" },
|
||||
new String[] {
|
||||
"a", null, "b", "c", null, "d" }, true);
|
||||
"a", "!HASLABEL!", "b", "c", null, "d" }, true);
|
||||
// Upper case specification will not work.
|
||||
assertGetBooleanValue("Multiple has label with needs dividers", HAS_LABEL,
|
||||
new String[] {
|
||||
"a", HAS_LABEL, "b", NEEDS_DIVIDER, HAS_LABEL.toUpperCase(), "d" },
|
||||
new String[] {
|
||||
"a", null, "b", NEEDS_DIVIDER, null, "d" }, true);
|
||||
"a", null, "b", NEEDS_DIVIDER, "!HASLABEL!", "d" }, true);
|
||||
}
|
||||
|
||||
private static void assertGetIntValue(String message, String key, int defaultValue,
|
||||
|
@ -613,9 +622,10 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
assertGetIntValue("Fixed column order 3", FIXED_COLUMN_ORDER, -1,
|
||||
new String[] { FIXED_COLUMN_ORDER + "3", "a", "b", "c" },
|
||||
new String[] { null, "a", "b", "c" }, 3);
|
||||
// Upper case specification will not work.
|
||||
assertGetIntValue("FIXED COLUMN ORDER 3", FIXED_COLUMN_ORDER, -1,
|
||||
new String[] { FIXED_COLUMN_ORDER.toUpperCase() + "3", "a", "b", "c" },
|
||||
new String[] { null, "a", "b", "c" }, 3);
|
||||
new String[] { "!FIXEDCOLUMNORDER!3", "a", "b", "c" }, -1);
|
||||
|
||||
assertGetIntValue("No fixed column order", FIXED_COLUMN_ORDER, -1,
|
||||
new String[] { "a", "b", "c" },
|
||||
|
@ -627,10 +637,11 @@ public class KeySpecParserTests extends AndroidTestCase {
|
|||
assertGetIntValue("Multiple fixed column order 3,5", FIXED_COLUMN_ORDER, -1,
|
||||
new String[] { FIXED_COLUMN_ORDER + "3", "a", FIXED_COLUMN_ORDER + "5", "b" },
|
||||
new String[] { null, "a", null, "b" }, 3);
|
||||
// Upper case specification will not work.
|
||||
assertGetIntValue("Multiple fixed column order 5,3 with has label", FIXED_COLUMN_ORDER, -1,
|
||||
new String[] {
|
||||
FIXED_COLUMN_ORDER.toUpperCase() + "5", HAS_LABEL, "a",
|
||||
FIXED_COLUMN_ORDER + "3", "b" },
|
||||
new String[] { null, HAS_LABEL, "a", null, "b" }, 5);
|
||||
new String[] { "!FIXEDCOLUMNORDER!5", HAS_LABEL, "a", null, "b" }, 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public final class KeyboardTextsSet {
|
|||
// Language to texts map.
|
||||
private static final HashMap<String, String[]> sLocaleToTextsMap =
|
||||
new HashMap<String, String[]>();
|
||||
private static final HashMap<String, Integer> sLowerCaseNameToIdsMap =
|
||||
private static final HashMap<String, Integer> sNameToIdsMap =
|
||||
new HashMap<String, Integer>();
|
||||
|
||||
private String[] mTexts;
|
||||
|
@ -77,19 +77,11 @@ public final class KeyboardTextsSet {
|
|||
}
|
||||
|
||||
public String getText(final String name) {
|
||||
String lowerCaseName = null;
|
||||
String text = mResourceNameToTextsMap.get(name);
|
||||
if (text == null) {
|
||||
lowerCaseName = name.toLowerCase();
|
||||
text = mResourceNameToTextsMap.get(lowerCaseName);
|
||||
}
|
||||
if (text != null) {
|
||||
return text;
|
||||
}
|
||||
Integer id = sLowerCaseNameToIdsMap.get(name);
|
||||
if (id == null) {
|
||||
id = sLowerCaseNameToIdsMap.get(lowerCaseName); // lowerCaseName != null
|
||||
}
|
||||
final Integer id = sNameToIdsMap.get(name);
|
||||
if (id == null) throw new RuntimeException("Unknown label: " + name);
|
||||
text = (id < mTexts.length) ? mTexts[id] : null;
|
||||
return (text == null) ? LANGUAGE_DEFAULT[id] : text;
|
||||
|
@ -131,7 +123,7 @@ public final class KeyboardTextsSet {
|
|||
static {
|
||||
int id = 0;
|
||||
for (final String name : NAMES) {
|
||||
sLowerCaseNameToIdsMap.put(name, id++);
|
||||
sNameToIdsMap.put(name, id++);
|
||||
}
|
||||
|
||||
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
|
||||
|
|
Loading…
Reference in a new issue