am 5bf55a86: Return null if "!text/" reference is an empty text

* commit '5bf55a86d0dd55ade42833fdb7cf654b2aeddb4e':
  Return null if "!text/" reference is an empty text
main
Tadashi G. Takaoka 2013-12-06 00:11:08 -08:00 committed by Android Git Automerger
commit 2b1e904195
2 changed files with 17 additions and 4 deletions

View File

@ -78,10 +78,10 @@ public final class KeySpecParser {
* or has no key specifications.
*/
public static String[] splitKeySpecs(final String text) {
final int size = text.length();
if (size == 0) {
if (TextUtils.isEmpty(text)) {
return null;
}
final int size = text.length();
// Optimization for one-letter key specification.
if (size == 1) {
return text.charAt(0) == COMMA ? null : new String[] { text };
@ -380,6 +380,9 @@ public final class KeySpecParser {
public static String resolveTextReference(final String rawText,
final KeyboardTextsSet textsSet) {
if (TextUtils.isEmpty(rawText)) {
return null;
}
int level = 0;
String text = rawText;
StringBuilder sb;
@ -392,7 +395,7 @@ public final class KeySpecParser {
final int prefixLen = PREFIX_TEXT.length();
final int size = text.length();
if (size < prefixLen) {
return text;
return TextUtils.isEmpty(text) ? null : text;
}
sb = null;
@ -421,7 +424,7 @@ public final class KeySpecParser {
text = sb.toString();
}
} while (sb != null);
return text;
return TextUtils.isEmpty(text) ? null : text;
}
private static int searchTextNameEnd(final String text, final int start) {

View File

@ -116,6 +116,16 @@ public class KeySpecParserSplitTests extends InstrumentationTestCase {
private static final String SURROGATE1 = PAIR1 + PAIR2;
private static final String SURROGATE2 = PAIR1 + PAIR2 + PAIR3;
public void testResolveNullText() {
assertNull("resolve null", KeySpecParser.resolveTextReference(
null, mTextsSet));
}
public void testResolveEmptyText() {
assertNull("resolve empty text", KeySpecParser.resolveTextReference(
"!text/empty_string", mTextsSet));
}
public void testSplitZero() {
assertTextArray("Empty string", "");
assertTextArray("Empty entry", ",");