diff --git a/core/java/com/android/internal/app/LocaleHelper.java b/core/java/com/android/internal/app/LocaleHelper.java index d418770e00bf3..707286e0fc4ca 100644 --- a/core/java/com/android/internal/app/LocaleHelper.java +++ b/core/java/com/android/internal/app/LocaleHelper.java @@ -18,6 +18,7 @@ package com.android.internal.app; import android.annotation.IntRange; import android.compat.annotation.UnsupportedAppUsage; +import android.icu.text.CaseMap; import android.icu.text.ListFormatter; import android.icu.util.ULocale; import android.os.LocaleList; @@ -35,43 +36,13 @@ public class LocaleHelper { /** * Sentence-case (first character uppercased). * - *
There is no good API available for this, not even in ICU. - * We can revisit this if we get some ICU support later.
- * - *There are currently several tickets requesting this feature:
- *A (clunky) option with the current ICU API is:
- * {{ - * BreakIterator breakIterator = BreakIterator.getSentenceInstance(locale); - * String result = UCharacter.toTitleCase(locale, - * source, breakIterator, UCharacter.TITLECASE_NO_LOWERCASE); - * }} - * - *That also means creating a BreakIterator for each locale. Expensive...
- * * @param str the string to sentence-case. * @param locale the locale used for the case conversion. * @return the string converted to sentence-case. */ public static String toSentenceCase(String str, Locale locale) { - if (str.isEmpty()) { - return str; - } - final int firstCodePointLen = str.offsetByCodePoints(0, 1); - return str.substring(0, firstCodePointLen).toUpperCase(locale) - + str.substring(firstCodePointLen); + // Titlecases only the character at index 0, don't touch anything else + return CaseMap.toTitle().wholeString().noLowercase().apply(locale, null, str); } /**