diff options
author | 2014-01-20 02:46:43 -0800 | |
---|---|---|
committer | 2014-01-20 02:46:43 -0800 | |
commit | 528bddec97a293228ce5336b1d75ecbe8dd3b318 (patch) | |
tree | 6169c331da11a8f5952b52ee38a34d75833c2a61 /java/src/com/android/inputmethod/latin/utils/StringUtils.java | |
parent | 1905a54b9acc89cdb84d12f024c0b345f927ddec (diff) | |
parent | c93cf1c398fbea8bde4b568dae1fbe2f8d9b4180 (diff) | |
download | latinime-528bddec97a293228ce5336b1d75ecbe8dd3b318.tar.gz latinime-528bddec97a293228ce5336b1d75ecbe8dd3b318.tar.xz latinime-528bddec97a293228ce5336b1d75ecbe8dd3b318.zip |
am c93cf1c3: Use sorted int[] to represent word separators
* commit 'c93cf1c398fbea8bde4b568dae1fbe2f8d9b4180':
Use sorted int[] to represent word separators
Diffstat (limited to 'java/src/com/android/inputmethod/latin/utils/StringUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/StringUtils.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java index 699a0b80e..5920c68f1 100644 --- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java @@ -272,39 +272,39 @@ public final class StringUtils { } public static boolean isIdenticalAfterCapitalizeEachWord(final String text, - final String separators) { - boolean needCapsNext = true; + final int[] sortedSeparators) { + boolean needsCapsNext = true; final int len = text.length(); for (int i = 0; i < len; i = text.offsetByCodePoints(i, 1)) { final int codePoint = text.codePointAt(i); if (Character.isLetter(codePoint)) { - if ((needCapsNext && !Character.isUpperCase(codePoint)) - || (!needCapsNext && !Character.isLowerCase(codePoint))) { + if ((needsCapsNext && !Character.isUpperCase(codePoint)) + || (!needsCapsNext && !Character.isLowerCase(codePoint))) { return false; } } // We need a capital letter next if this is a separator. - needCapsNext = (-1 != separators.indexOf(codePoint)); + needsCapsNext = (Arrays.binarySearch(sortedSeparators, codePoint) >= 0); } return true; } // TODO: like capitalizeFirst*, this does not work perfectly for Dutch because of the IJ digraph // which should be capitalized together in *some* cases. - public static String capitalizeEachWord(final String text, final String separators, + public static String capitalizeEachWord(final String text, final int[] sortedSeparators, final Locale locale) { final StringBuilder builder = new StringBuilder(); - boolean needCapsNext = true; + boolean needsCapsNext = true; final int len = text.length(); for (int i = 0; i < len; i = text.offsetByCodePoints(i, 1)) { final String nextChar = text.substring(i, text.offsetByCodePoints(i, 1)); - if (needCapsNext) { + if (needsCapsNext) { builder.append(nextChar.toUpperCase(locale)); } else { builder.append(nextChar.toLowerCase(locale)); } // We need a capital letter next if this is a separator. - needCapsNext = (-1 != separators.indexOf(nextChar.codePointAt(0))); + needsCapsNext = (Arrays.binarySearch(sortedSeparators, nextChar.codePointAt(0)) >= 0); } return builder.toString(); } |