diff options
author | 2013-05-15 12:52:55 -0700 | |
---|---|---|
committer | 2013-05-15 12:52:55 -0700 | |
commit | 941e8bbaa97f8f3a09a072cf96120e5058949f19 (patch) | |
tree | 8f892b16d34116c54e48a266216aa5bbbbe45c62 /java/src/com/android/inputmethod/latin/StringUtils.java | |
parent | e90fe9c3a42e440da477932704bf4cc42c94f722 (diff) | |
parent | a01ab9ea3580d95e87f3357b2612fb84971b3bfd (diff) | |
download | latinime-941e8bbaa97f8f3a09a072cf96120e5058949f19.tar.gz latinime-941e8bbaa97f8f3a09a072cf96120e5058949f19.tar.xz latinime-941e8bbaa97f8f3a09a072cf96120e5058949f19.zip |
am a01ab9ea: am 565ced45: Merge "Refactor StringUtils.findPrefixedString to findValueOfKey"
* commit 'a01ab9ea3580d95e87f3357b2612fb84971b3bfd':
Refactor StringUtils.findPrefixedString to findValueOfKey
Diffstat (limited to '')
-rw-r--r-- | java/src/com/android/inputmethod/latin/StringUtils.java | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java index d5ee58a63..5ff101f7a 100644 --- a/java/src/com/android/inputmethod/latin/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -65,17 +65,24 @@ public final class StringUtils { } /** - * Find a string that start with specified prefix from an array. + * Find a value that has a specified key from an array of key-comma-value. * - * @param prefix a prefix string to find. - * @param array an string array to be searched. - * @return the rest part of the string that starts with the prefix. + * @param key a key string to find. + * @param array an array of key-comma-value string to be searched. + * @return the value part of the first string that has a specified key. * Returns null if it couldn't be found. */ - public static String findPrefixedString(final String prefix, final String[] array) { + public static String findValueOfKey(final String key, final String[] array) { + if (array == null) { + return null; + } for (final String element : array) { - if (element.startsWith(prefix)) { - return element.substring(prefix.length()); + final int posComma = element.indexOf(','); + if (posComma < 0) { + throw new RuntimeException("Element has no comma: " + element); + } + if (element.substring(0, posComma).equals(key)) { + return element.substring(posComma + 1); } } return null; |