diff options
author | 2013-05-10 17:44:39 +0900 | |
---|---|---|
committer | 2013-05-10 18:44:04 +0900 | |
commit | 6d3d2ae0647792c60728b916e25321e93f6f971f (patch) | |
tree | e12c15c1835ade6ee9f4e40dade4e62fa4f98a38 /java/src/com/android/inputmethod/latin/StringUtils.java | |
parent | 5ffa5bf3ba7d169912d163790e461ab8d5aca30a (diff) | |
download | latinime-6d3d2ae0647792c60728b916e25321e93f6f971f.tar.gz latinime-6d3d2ae0647792c60728b916e25321e93f6f971f.tar.xz latinime-6d3d2ae0647792c60728b916e25321e93f6f971f.zip |
Refactor StringUtils.findPrefixedString to findValueOfKey
Bug: 8556975
Change-Id: I275c99db8a0d10594a5a8c0c27ebc1a87495c307
Diffstat (limited to 'java/src/com/android/inputmethod/latin/StringUtils.java')
-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; |