diff options
author | 2014-11-19 13:45:21 +0900 | |
---|---|---|
committer | 2014-11-19 19:08:05 +0900 | |
commit | 6c47403e27fd703ece844f4b1b24632721da1772 (patch) | |
tree | 3d92649aecef08b1c138f09d1b1146421421562e /common/src/com/android | |
parent | 0cf0bfaa752a21303086e573e2ba78fd77cf4140 (diff) | |
download | latinime-6c47403e27fd703ece844f4b1b24632721da1772.tar.gz latinime-6c47403e27fd703ece844f4b1b24632721da1772.tar.xz latinime-6c47403e27fd703ece844f4b1b24632721da1772.zip |
Rename StringUtils methods that handle title case manipulation
Change-Id: Iee0dd077a0423f110f4f8dad0f04933045baef2a
Diffstat (limited to 'common/src/com/android')
-rw-r--r-- | common/src/com/android/inputmethod/latin/common/StringUtils.java | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/common/src/com/android/inputmethod/latin/common/StringUtils.java b/common/src/com/android/inputmethod/latin/common/StringUtils.java index 463eabbee..572f0cd9b 100644 --- a/common/src/com/android/inputmethod/latin/common/StringUtils.java +++ b/common/src/com/android/inputmethod/latin/common/StringUtils.java @@ -201,20 +201,20 @@ public final class StringUtils { public static String capitalizeFirstCodePoint(@Nonnull final String s, @Nonnull final Locale locale) { if (s.length() <= 1) { - return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, locale); + return s.toUpperCase(getLocaleUsedForToTitleCase(locale)); } // Please refer to the comment below in // {@link #capitalizeFirstAndDowncaseRest(String,Locale)} as this has the same shortcomings final int cutoff = s.offsetByCodePoints(0, 1); - return toUpperCaseOfStringForLocale( - s.substring(0, cutoff), true /* needsToUpperCase */, locale) + s.substring(cutoff); + return s.substring(0, cutoff).toUpperCase(getLocaleUsedForToTitleCase(locale)) + + s.substring(cutoff); } @Nonnull public static String capitalizeFirstAndDowncaseRest(@Nonnull final String s, @Nonnull final Locale locale) { if (s.length() <= 1) { - return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, locale); + return s.toUpperCase(getLocaleUsedForToTitleCase(locale)); } // TODO: fix the bugs below // - It does not work for Serbian, because it fails to account for the "lj" character, @@ -224,9 +224,8 @@ public final class StringUtils { // be capitalized as "IJ" as if they were a single letter in most words (not all). If the // unicode char for the ligature is used however, it works. final int cutoff = s.offsetByCodePoints(0, 1); - final String titleCaseFirstLetter = toUpperCaseOfStringForLocale( - s.substring(0, cutoff), true /* needsToUpperCase */, locale); - return titleCaseFirstLetter + s.substring(cutoff).toLowerCase(locale); + return s.substring(0, cutoff).toUpperCase(getLocaleUsedForToTitleCase(locale)) + + s.substring(cutoff).toLowerCase(locale); } @Nonnull @@ -599,24 +598,22 @@ public final class StringUtils { } @Nullable - public static String toUpperCaseOfStringForLocale(@Nullable final String text, - final boolean needsToUpperCase, @Nonnull final Locale locale) { - if (text == null || !needsToUpperCase) { - return text; + public static String toTitleCaseOfKeyLabel(@Nullable final String label, + @Nonnull final Locale locale) { + if (label == null) { + return label; } - return text.toUpperCase(getLocaleUsedForToTitleCase(locale)); + return label.toUpperCase(getLocaleUsedForToTitleCase(locale)); } - public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase, - @Nonnull final Locale locale) { - if (!Constants.isLetterCode(code) || !needsToUpperCase) { + public static int toTitleCaseOfKeyCode(final int code, @Nonnull final Locale locale) { + if (!Constants.isLetterCode(code)) { return code; } - final String text = newSingleCodePointString(code); - final String casedText = toUpperCaseOfStringForLocale( - text, needsToUpperCase, locale); - return codePointCount(casedText) == 1 - ? casedText.codePointAt(0) : Constants.CODE_UNSPECIFIED; + final String label = newSingleCodePointString(code); + final String titleCaseLabel = toTitleCaseOfKeyLabel(label, locale); + return codePointCount(titleCaseLabel) == 1 + ? titleCaseLabel.codePointAt(0) : Constants.CODE_UNSPECIFIED; } public static int getTrailingSingleQuotesCount(@Nonnull final CharSequence charSequence) { |