am 02a534d1: Merge "Treat a sole "|" as a special case of key label"
* commit '02a534d13f5e04173efdf10a509de8aa85d2d6a5': Treat a sole "|" as a special case of key labelmain
commit
15377bc11f
|
@ -84,14 +84,18 @@ public final class KeySpecParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int indexOfLabelEnd(final String keySpec) {
|
private static int indexOfLabelEnd(final String keySpec) {
|
||||||
|
final int length = keySpec.length();
|
||||||
if (keySpec.indexOf(BACKSLASH) < 0) {
|
if (keySpec.indexOf(BACKSLASH) < 0) {
|
||||||
final int labelEnd = keySpec.indexOf(VERTICAL_BAR);
|
final int labelEnd = keySpec.indexOf(VERTICAL_BAR);
|
||||||
if (labelEnd == 0) {
|
if (labelEnd == 0) {
|
||||||
|
if (length == 1) {
|
||||||
|
// Treat a sole vertical bar as a special case of key label.
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
throw new KeySpecParserError("Empty label");
|
throw new KeySpecParserError("Empty label");
|
||||||
}
|
}
|
||||||
return labelEnd;
|
return labelEnd;
|
||||||
}
|
}
|
||||||
final int length = keySpec.length();
|
|
||||||
for (int pos = 0; pos < length; pos++) {
|
for (int pos = 0; pos < length; pos++) {
|
||||||
final char c = keySpec.charAt(pos);
|
final char c = keySpec.charAt(pos);
|
||||||
if (c == BACKSLASH && pos + 1 < length) {
|
if (c == BACKSLASH && pos + 1 < length) {
|
||||||
|
|
|
@ -101,7 +101,9 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
|
||||||
"a", null, ICON_UNDEFINED, 'a');
|
"a", null, ICON_UNDEFINED, 'a');
|
||||||
assertParser("Single surrogate", SURROGATE_PAIR1,
|
assertParser("Single surrogate", SURROGATE_PAIR1,
|
||||||
SURROGATE_PAIR1, null, ICON_UNDEFINED, SURROGATE_CODE1);
|
SURROGATE_PAIR1, null, ICON_UNDEFINED, SURROGATE_CODE1);
|
||||||
assertParser("Single escaped bar", "\\|",
|
assertParser("Sole vertical bar", "|",
|
||||||
|
"|", null, ICON_UNDEFINED, '|');
|
||||||
|
assertParser("Single escaped vertical bar", "\\|",
|
||||||
"|", null, ICON_UNDEFINED, '|');
|
"|", null, ICON_UNDEFINED, '|');
|
||||||
assertParser("Single escaped escape", "\\\\",
|
assertParser("Single escaped escape", "\\\\",
|
||||||
"\\", null, ICON_UNDEFINED, '\\');
|
"\\", null, ICON_UNDEFINED, '\\');
|
||||||
|
@ -251,8 +253,6 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFormatError() {
|
public void testFormatError() {
|
||||||
assertParserError("Single bar", "|",
|
|
||||||
"|", null, ICON_UNDEFINED, '|');
|
|
||||||
assertParserError("Empty label with outputText", "|a",
|
assertParserError("Empty label with outputText", "|a",
|
||||||
null, "a", ICON_UNDEFINED, CODE_UNSPECIFIED);
|
null, "a", ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||||
assertParserError("Empty label with code", "|" + CODE_SETTINGS,
|
assertParserError("Empty label with code", "|" + CODE_SETTINGS,
|
||||||
|
@ -261,8 +261,6 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
|
||||||
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
"a", null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
||||||
assertParserError("Empty outputText with icon", ICON_SETTINGS + "|",
|
assertParserError("Empty outputText with icon", ICON_SETTINGS + "|",
|
||||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||||
assertParserError("Empty icon and code", "|",
|
|
||||||
null, null, ICON_UNDEFINED, CODE_UNSPECIFIED);
|
|
||||||
assertParserError("Icon without code", ICON_SETTINGS,
|
assertParserError("Icon without code", ICON_SETTINGS,
|
||||||
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
null, null, mSettingsIconId, CODE_UNSPECIFIED);
|
||||||
assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc",
|
assertParserError("Non existing icon", ICON_NON_EXISTING + "|abc",
|
||||||
|
|
Loading…
Reference in New Issue