Merge "Disable sentence-case for Georgian" into sc-dev

This commit is contained in:
Victor Chang
2021-05-24 15:57:25 +00:00
committed by Android (Google) Code Review

View File

@@ -18,6 +18,7 @@ package com.android.internal.app;
import android.annotation.IntRange; import android.annotation.IntRange;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.icu.text.CaseMap;
import android.icu.text.ListFormatter; import android.icu.text.ListFormatter;
import android.icu.util.ULocale; import android.icu.util.ULocale;
import android.os.LocaleList; import android.os.LocaleList;
@@ -35,43 +36,13 @@ public class LocaleHelper {
/** /**
* Sentence-case (first character uppercased). * 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 str the string to sentence-case.
* @param locale the locale used for the case conversion. * @param locale the locale used for the case conversion.
* @return the string converted to sentence-case. * @return the string converted to sentence-case.
*/ */
public static String toSentenceCase(String str, Locale locale) { public static String toSentenceCase(String str, Locale locale) {
if (str.isEmpty()) { // Titlecases only the character at index 0, don't touch anything else
return str; return CaseMap.toTitle().wholeString().noLowercase().apply(locale, null, str);
}
final int firstCodePointLen = str.offsetByCodePoints(0, 1);
return str.substring(0, firstCodePointLen).toUpperCase(locale)
+ str.substring(firstCodePointLen);
} }
/** /**