Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa10ca3 authored by Victor Chang's avatar Victor Chang Committed by Automerger Merge Worker
Browse files

Merge "Disable sentence-case for Georgian" into sc-dev am: 0946a97d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14489968

Change-Id: I0aa295994f22289363af9f4909409cc07b390255
parents 9b3ac457 0946a97d
Loading
Loading
Loading
Loading
+3 −32
Original line number Diff line number Diff line
@@ -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);
    }

    /**