am a9e1db66: Merge "Decimal number is treated as outputText"
* commit 'a9e1db6636c69a9bf3c1a7bd6753781dd68bff0f': Decimal number is treated as outputTextmain
commit
3a82e5e421
|
@ -57,8 +57,15 @@ public final class KeySpecParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasCode(final String keySpec, final int labelEnd) {
|
private static boolean hasCode(final String keySpec, final int labelEnd) {
|
||||||
if (labelEnd > 0 && labelEnd + 1 < keySpec.length()
|
if (labelEnd <= 0 || labelEnd + 1 >= keySpec.length()) {
|
||||||
&& keySpec.startsWith(KeyboardCodesSet.PREFIX_CODE, labelEnd + 1)) {
|
return false;
|
||||||
|
}
|
||||||
|
if (keySpec.startsWith(KeyboardCodesSet.PREFIX_CODE, labelEnd + 1)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// This is a workaround to have a key that has a supplementary code point. We can't put a
|
||||||
|
// string in resource as a XML entity of a supplementary code point or a surrogate pair.
|
||||||
|
if (keySpec.startsWith(PREFIX_HEX, labelEnd + 1)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -203,19 +210,20 @@ public final class KeySpecParser {
|
||||||
return (StringUtils.codePointCount(label) == 1) ? label.codePointAt(0) : CODE_OUTPUT_TEXT;
|
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,
|
public static int parseCode(final String text, final KeyboardCodesSet codesSet,
|
||||||
final int defCode) {
|
final int defaultCode) {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
return defCode;
|
return defaultCode;
|
||||||
}
|
}
|
||||||
if (text.startsWith(KeyboardCodesSet.PREFIX_CODE)) {
|
if (text.startsWith(KeyboardCodesSet.PREFIX_CODE)) {
|
||||||
return codesSet.getCode(text.substring(KeyboardCodesSet.PREFIX_CODE.length()));
|
return codesSet.getCode(text.substring(KeyboardCodesSet.PREFIX_CODE.length()));
|
||||||
}
|
}
|
||||||
|
// This is a workaround to have a key that has a supplementary code point. We can't put a
|
||||||
|
// string in resource as a XML entity of a supplementary code point or a surrogate pair.
|
||||||
if (text.startsWith(PREFIX_HEX)) {
|
if (text.startsWith(PREFIX_HEX)) {
|
||||||
return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16);
|
return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16);
|
||||||
}
|
}
|
||||||
return Integer.parseInt(text);
|
return defaultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getIconId(final String keySpec) {
|
public static int getIconId(final String keySpec) {
|
||||||
|
|
|
@ -218,6 +218,32 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
|
||||||
"a|c", null, ICON_UNDEFINED, mCodeSettings);
|
"a|c", null, ICON_UNDEFINED, mCodeSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCodes() {
|
||||||
|
assertParser("Hexadecimal code", "a|0x1000",
|
||||||
|
"a", null, ICON_UNDEFINED, 0x1000);
|
||||||
|
assertParserError("Illegal hexadecimal code", "a|0x100X",
|
||||||
|
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||||
|
assertParser("Escaped hexadecimal code 1", "a|\\0x1000",
|
||||||
|
"a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||||
|
assertParser("Escaped hexadecimal code 2", "a|0\\x1000",
|
||||||
|
"a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||||
|
assertParser("Escaped hexadecimal code 2", "a|0\\x1000",
|
||||||
|
"a", "0x1000", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||||
|
assertParserError("Illegally escaped hexadecimal code", "a|0x1\\000",
|
||||||
|
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||||
|
// This is a workaround to have a key that has a supplementary code point. We can't put a
|
||||||
|
// string in resource as a XML entity of a supplementary code point or a surrogate pair.
|
||||||
|
// TODO: Should pass this test.
|
||||||
|
// assertParser("Hexadecimal supplementary code", String.format("a|0x%06x", SURROGATE_CODE2),
|
||||||
|
// SURROGATE_PAIR2, null, ICON_UNDEFINED, SURROGATE_CODE2);
|
||||||
|
assertParser("Zero is treated as output text", "a|0",
|
||||||
|
"a", null, ICON_UNDEFINED, '0');
|
||||||
|
assertParser("Digit is treated as output text", "a|3",
|
||||||
|
"a", null, ICON_UNDEFINED, '3');
|
||||||
|
assertParser("Decimal number is treated as an output text", "a|2014",
|
||||||
|
"a", "2014", ICON_UNDEFINED, CODE_OUTPUT_TEXT);
|
||||||
|
}
|
||||||
|
|
||||||
public void testIcons() {
|
public void testIcons() {
|
||||||
assertParser("Icon with single letter", ICON_SETTINGS + "|a",
|
assertParser("Icon with single letter", ICON_SETTINGS + "|a",
|
||||||
null, null, mSettingsIconId, 'a');
|
null, null, mSettingsIconId, 'a');
|
||||||
|
|
Loading…
Reference in New Issue