Merge "Disable sentence-case for Georgian" into sc-dev am: 0946a97d06 am: 0d9d0d0521
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14489968 Change-Id: Ieaf81e27b4c6a783786a667ff4057b7ed781bc9c
This commit is contained in:
@@ -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).
|
||||
*
|
||||
* <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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user