Loading core/java/com/android/internal/app/LocaleHelper.java +3 −32 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -35,43 +36,13 @@ public class LocaleHelper { /** * Sentence-case (first character uppercased). * * <p>There is no good API available for this, not even in ICU. * We can revisit this if we get some ICU support later.</p> * * <p>There are currently several tickets requesting this feature:</p> * <ul> * <li>ICU needs to provide an easy way to titlecase only one first letter * http://bugs.icu-project.org/trac/ticket/11729</li> * <li>Add "initial case" * http://bugs.icu-project.org/trac/ticket/8394</li> * <li>Add code for initialCase, toTitlecase don't modify after Lt, * avoid 49Ers, low-level language-specific casing * http://bugs.icu-project.org/trac/ticket/10410</li> * <li>BreakIterator.getFirstInstance: Often you need to titlecase just the first * word, and leave the rest of the string alone. (closed as duplicate) * http://bugs.icu-project.org/trac/ticket/8946</li> * </ul> * * <p>A (clunky) option with the current ICU API is:</p> * {{ * BreakIterator breakIterator = BreakIterator.getSentenceInstance(locale); * String result = UCharacter.toTitleCase(locale, * source, breakIterator, UCharacter.TITLECASE_NO_LOWERCASE); * }} * * <p>That also means creating a BreakIterator for each locale. Expensive...</p> * * @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); } /** Loading Loading
core/java/com/android/internal/app/LocaleHelper.java +3 −32 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -35,43 +36,13 @@ public class LocaleHelper { /** * Sentence-case (first character uppercased). * * <p>There is no good API available for this, not even in ICU. * We can revisit this if we get some ICU support later.</p> * * <p>There are currently several tickets requesting this feature:</p> * <ul> * <li>ICU needs to provide an easy way to titlecase only one first letter * http://bugs.icu-project.org/trac/ticket/11729</li> * <li>Add "initial case" * http://bugs.icu-project.org/trac/ticket/8394</li> * <li>Add code for initialCase, toTitlecase don't modify after Lt, * avoid 49Ers, low-level language-specific casing * http://bugs.icu-project.org/trac/ticket/10410</li> * <li>BreakIterator.getFirstInstance: Often you need to titlecase just the first * word, and leave the rest of the string alone. (closed as duplicate) * http://bugs.icu-project.org/trac/ticket/8946</li> * </ul> * * <p>A (clunky) option with the current ICU API is:</p> * {{ * BreakIterator breakIterator = BreakIterator.getSentenceInstance(locale); * String result = UCharacter.toTitleCase(locale, * source, breakIterator, UCharacter.TITLECASE_NO_LOWERCASE); * }} * * <p>That also means creating a BreakIterator for each locale. Expensive...</p> * * @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); } /** Loading