aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-11-19 09:29:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-11-19 09:29:20 +0000
commit0cf0bfaa752a21303086e573e2ba78fd77cf4140 (patch)
tree3de66cc4f6623e30b5c6e93d0a08788a1a5ef867 /common
parenta39ecd071cd727a59e7cbd1423c1cda7d2f3cb71 (diff)
parentf62b5d633d17b94a7ea46c968e073fdaa3fcbe15 (diff)
downloadlatinime-0cf0bfaa752a21303086e573e2ba78fd77cf4140.tar.gz
latinime-0cf0bfaa752a21303086e573e2ba78fd77cf4140.tar.xz
latinime-0cf0bfaa752a21303086e573e2ba78fd77cf4140.zip
Merge "Fix Greek accented upper case letters"
Diffstat (limited to 'common')
-rw-r--r--common/src/com/android/inputmethod/latin/common/StringUtils.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/common/src/com/android/inputmethod/latin/common/StringUtils.java b/common/src/com/android/inputmethod/latin/common/StringUtils.java
index be7260308..463eabbee 100644
--- a/common/src/com/android/inputmethod/latin/common/StringUtils.java
+++ b/common/src/com/android/inputmethod/latin/common/StringUtils.java
@@ -201,22 +201,22 @@ public final class StringUtils {
public static String capitalizeFirstCodePoint(@Nonnull final String s,
@Nonnull final Locale locale) {
if (s.length() <= 1) {
- return s.toUpperCase(locale);
+ return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, 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 s.substring(0, cutoff).toUpperCase(locale) + s.substring(cutoff);
+ return toUpperCaseOfStringForLocale(
+ s.substring(0, cutoff), true /* needsToUpperCase */, locale) + s.substring(cutoff);
}
@Nonnull
public static String capitalizeFirstAndDowncaseRest(@Nonnull final String s,
@Nonnull final Locale locale) {
if (s.length() <= 1) {
- return s.toUpperCase(locale);
+ return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, locale);
}
// TODO: fix the bugs below
- // - This does not work for Greek, because it returns upper case instead of title case.
// - It does not work for Serbian, because it fails to account for the "lj" character,
// which should be "Lj" in title case and "LJ" in upper case.
// - It does not work for Dutch, because it fails to account for the "ij" digraph when it's
@@ -224,7 +224,9 @@ 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);
- return s.substring(0, cutoff).toUpperCase(locale) + s.substring(cutoff).toLowerCase(locale);
+ final String titleCaseFirstLetter = toUpperCaseOfStringForLocale(
+ s.substring(0, cutoff), true /* needsToUpperCase */, locale);
+ return titleCaseFirstLetter + s.substring(cutoff).toLowerCase(locale);
}
@Nonnull
@@ -584,13 +586,25 @@ public final class StringUtils {
return bytes;
}
+ private static final String LANGUAGE_GREEK = "el";
+
+ @Nonnull
+ private static Locale getLocaleUsedForToTitleCase(@Nonnull final Locale locale) {
+ // In Greek locale {@link String#toUpperCase(Locale)} eliminates accents from its result.
+ // In order to get accented upper case letter, {@link Locale#ROOT} should be used.
+ if (LANGUAGE_GREEK.equals(locale.getLanguage())) {
+ return Locale.ROOT;
+ }
+ return locale;
+ }
+
@Nullable
public static String toUpperCaseOfStringForLocale(@Nullable final String text,
final boolean needsToUpperCase, @Nonnull final Locale locale) {
if (text == null || !needsToUpperCase) {
return text;
}
- return text.toUpperCase(locale);
+ return text.toUpperCase(getLocaleUsedForToTitleCase(locale));
}
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,