Rename StringUtils methods that handle title case manipulation
Change-Id: Iee0dd077a0423f110f4f8dad0f04933045baef2amain
parent
0cf0bfaa75
commit
6c47403e27
|
@ -201,20 +201,20 @@ public final class StringUtils {
|
||||||
public static String capitalizeFirstCodePoint(@Nonnull final String s,
|
public static String capitalizeFirstCodePoint(@Nonnull final String s,
|
||||||
@Nonnull final Locale locale) {
|
@Nonnull final Locale locale) {
|
||||||
if (s.length() <= 1) {
|
if (s.length() <= 1) {
|
||||||
return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, locale);
|
return s.toUpperCase(getLocaleUsedForToTitleCase(locale));
|
||||||
}
|
}
|
||||||
// Please refer to the comment below in
|
// Please refer to the comment below in
|
||||||
// {@link #capitalizeFirstAndDowncaseRest(String,Locale)} as this has the same shortcomings
|
// {@link #capitalizeFirstAndDowncaseRest(String,Locale)} as this has the same shortcomings
|
||||||
final int cutoff = s.offsetByCodePoints(0, 1);
|
final int cutoff = s.offsetByCodePoints(0, 1);
|
||||||
return toUpperCaseOfStringForLocale(
|
return s.substring(0, cutoff).toUpperCase(getLocaleUsedForToTitleCase(locale))
|
||||||
s.substring(0, cutoff), true /* needsToUpperCase */, locale) + s.substring(cutoff);
|
+ s.substring(cutoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String capitalizeFirstAndDowncaseRest(@Nonnull final String s,
|
public static String capitalizeFirstAndDowncaseRest(@Nonnull final String s,
|
||||||
@Nonnull final Locale locale) {
|
@Nonnull final Locale locale) {
|
||||||
if (s.length() <= 1) {
|
if (s.length() <= 1) {
|
||||||
return toUpperCaseOfStringForLocale(s, true /* needsToUpperCase */, locale);
|
return s.toUpperCase(getLocaleUsedForToTitleCase(locale));
|
||||||
}
|
}
|
||||||
// TODO: fix the bugs below
|
// TODO: fix the bugs below
|
||||||
// - It does not work for Serbian, because it fails to account for the "lj" character,
|
// - It does not work for Serbian, because it fails to account for the "lj" character,
|
||||||
|
@ -224,9 +224,8 @@ public final class StringUtils {
|
||||||
// be capitalized as "IJ" as if they were a single letter in most words (not all). If the
|
// be capitalized as "IJ" as if they were a single letter in most words (not all). If the
|
||||||
// unicode char for the ligature is used however, it works.
|
// unicode char for the ligature is used however, it works.
|
||||||
final int cutoff = s.offsetByCodePoints(0, 1);
|
final int cutoff = s.offsetByCodePoints(0, 1);
|
||||||
final String titleCaseFirstLetter = toUpperCaseOfStringForLocale(
|
return s.substring(0, cutoff).toUpperCase(getLocaleUsedForToTitleCase(locale))
|
||||||
s.substring(0, cutoff), true /* needsToUpperCase */, locale);
|
+ s.substring(cutoff).toLowerCase(locale);
|
||||||
return titleCaseFirstLetter + s.substring(cutoff).toLowerCase(locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -599,24 +598,22 @@ public final class StringUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String toUpperCaseOfStringForLocale(@Nullable final String text,
|
public static String toTitleCaseOfKeyLabel(@Nullable final String label,
|
||||||
final boolean needsToUpperCase, @Nonnull final Locale locale) {
|
@Nonnull final Locale locale) {
|
||||||
if (text == null || !needsToUpperCase) {
|
if (label == null) {
|
||||||
return text;
|
return label;
|
||||||
}
|
}
|
||||||
return text.toUpperCase(getLocaleUsedForToTitleCase(locale));
|
return label.toUpperCase(getLocaleUsedForToTitleCase(locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,
|
public static int toTitleCaseOfKeyCode(final int code, @Nonnull final Locale locale) {
|
||||||
@Nonnull final Locale locale) {
|
if (!Constants.isLetterCode(code)) {
|
||||||
if (!Constants.isLetterCode(code) || !needsToUpperCase) {
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
final String text = newSingleCodePointString(code);
|
final String label = newSingleCodePointString(code);
|
||||||
final String casedText = toUpperCaseOfStringForLocale(
|
final String titleCaseLabel = toTitleCaseOfKeyLabel(label, locale);
|
||||||
text, needsToUpperCase, locale);
|
return codePointCount(titleCaseLabel) == 1
|
||||||
return codePointCount(casedText) == 1
|
? titleCaseLabel.codePointAt(0) : Constants.CODE_UNSPECIFIED;
|
||||||
? casedText.codePointAt(0) : Constants.CODE_UNSPECIFIED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTrailingSingleQuotesCount(@Nonnull final CharSequence charSequence) {
|
public static int getTrailingSingleQuotesCount(@Nonnull final CharSequence charSequence) {
|
||||||
|
|
|
@ -341,17 +341,24 @@ public class Key implements Comparable<Key> {
|
||||||
// code point nor as a surrogate pair.
|
// code point nor as a surrogate pair.
|
||||||
mLabel = new StringBuilder().appendCodePoint(code).toString();
|
mLabel = new StringBuilder().appendCodePoint(code).toString();
|
||||||
} else {
|
} else {
|
||||||
mLabel = StringUtils.toUpperCaseOfStringForLocale(
|
final String label = KeySpecParser.getLabel(keySpec);
|
||||||
KeySpecParser.getLabel(keySpec), needsToUpcase, localeForUpcasing);
|
mLabel = needsToUpcase
|
||||||
|
? StringUtils.toTitleCaseOfKeyLabel(label, localeForUpcasing)
|
||||||
|
: label;
|
||||||
}
|
}
|
||||||
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
|
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
|
||||||
mHintLabel = null;
|
mHintLabel = null;
|
||||||
} else {
|
} else {
|
||||||
mHintLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
final String hintLabel = style.getString(
|
||||||
R.styleable.Keyboard_Key_keyHintLabel), needsToUpcase, localeForUpcasing);
|
keyAttr, R.styleable.Keyboard_Key_keyHintLabel);
|
||||||
|
mHintLabel = needsToUpcase
|
||||||
|
? StringUtils.toTitleCaseOfKeyLabel(hintLabel, localeForUpcasing)
|
||||||
|
: hintLabel;
|
||||||
|
}
|
||||||
|
String outputText = KeySpecParser.getOutputText(keySpec);
|
||||||
|
if (needsToUpcase) {
|
||||||
|
outputText = StringUtils.toTitleCaseOfKeyLabel(outputText, localeForUpcasing);
|
||||||
}
|
}
|
||||||
String outputText = StringUtils.toUpperCaseOfStringForLocale(
|
|
||||||
KeySpecParser.getOutputText(keySpec), needsToUpcase, localeForUpcasing);
|
|
||||||
// Choose the first letter of the label as primary code if not specified.
|
// Choose the first letter of the label as primary code if not specified.
|
||||||
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
|
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
|
||||||
&& !TextUtils.isEmpty(mLabel)) {
|
&& !TextUtils.isEmpty(mLabel)) {
|
||||||
|
@ -377,12 +384,14 @@ public class Key implements Comparable<Key> {
|
||||||
mCode = CODE_OUTPUT_TEXT;
|
mCode = CODE_OUTPUT_TEXT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mCode = StringUtils.toUpperCaseOfCodeForLocale(code, needsToUpcase, localeForUpcasing);
|
mCode = needsToUpcase ? StringUtils.toTitleCaseOfKeyCode(code, localeForUpcasing)
|
||||||
|
: code;
|
||||||
}
|
}
|
||||||
final int altCodeInAttr = KeySpecParser.parseCode(
|
final int altCodeInAttr = KeySpecParser.parseCode(
|
||||||
style.getString(keyAttr, R.styleable.Keyboard_Key_altCode), CODE_UNSPECIFIED);
|
style.getString(keyAttr, R.styleable.Keyboard_Key_altCode), CODE_UNSPECIFIED);
|
||||||
final int altCode = StringUtils.toUpperCaseOfCodeForLocale(
|
final int altCode = needsToUpcase
|
||||||
altCodeInAttr, needsToUpcase, localeForUpcasing);
|
? StringUtils.toTitleCaseOfKeyCode(altCodeInAttr, localeForUpcasing)
|
||||||
|
: altCodeInAttr;
|
||||||
mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode,
|
mOptionalAttributes = OptionalAttributes.newInstance(outputText, altCode,
|
||||||
disabledIconId, visualInsetsLeft, visualInsetsRight);
|
disabledIconId, visualInsetsLeft, visualInsetsRight);
|
||||||
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
|
mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
|
||||||
|
|
|
@ -57,7 +57,6 @@ import com.android.inputmethod.latin.RichInputMethodSubtype;
|
||||||
import com.android.inputmethod.latin.SuggestedWords;
|
import com.android.inputmethod.latin.SuggestedWords;
|
||||||
import com.android.inputmethod.latin.common.Constants;
|
import com.android.inputmethod.latin.common.Constants;
|
||||||
import com.android.inputmethod.latin.common.CoordinateUtils;
|
import com.android.inputmethod.latin.common.CoordinateUtils;
|
||||||
import com.android.inputmethod.latin.common.StringUtils;
|
|
||||||
import com.android.inputmethod.latin.settings.DebugSettings;
|
import com.android.inputmethod.latin.settings.DebugSettings;
|
||||||
import com.android.inputmethod.latin.utils.TypefaceUtils;
|
import com.android.inputmethod.latin.utils.TypefaceUtils;
|
||||||
|
|
||||||
|
@ -874,8 +873,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
||||||
final Locale[] locales = subtype.getLocales();
|
final Locale[] locales = subtype.getLocales();
|
||||||
final String[] languages = new String[locales.length];
|
final String[] languages = new String[locales.length];
|
||||||
for (int i = 0; i < locales.length; ++i) {
|
for (int i = 0; i < locales.length; ++i) {
|
||||||
languages[i] = StringUtils.toUpperCaseOfStringForLocale(
|
languages[i] = locales[i].getLanguage().toUpperCase(Locale.ROOT);
|
||||||
locales[i].getLanguage(), true /* needsToUpperCase */, Locale.ROOT);
|
|
||||||
}
|
}
|
||||||
return TextUtils.join(" / ", languages);
|
return TextUtils.join(" / ", languages);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,11 @@ public final class MoreKeySpec {
|
||||||
if (TextUtils.isEmpty(moreKeySpec)) {
|
if (TextUtils.isEmpty(moreKeySpec)) {
|
||||||
throw new KeySpecParser.KeySpecParserError("Empty more key spec");
|
throw new KeySpecParser.KeySpecParserError("Empty more key spec");
|
||||||
}
|
}
|
||||||
mLabel = StringUtils.toUpperCaseOfStringForLocale(
|
final String label = KeySpecParser.getLabel(moreKeySpec);
|
||||||
KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale);
|
mLabel = needsToUpperCase ? StringUtils.toTitleCaseOfKeyLabel(label, locale) : label;
|
||||||
final int code = StringUtils.toUpperCaseOfCodeForLocale(
|
final int codeInSpec = KeySpecParser.getCode(moreKeySpec);
|
||||||
KeySpecParser.getCode(moreKeySpec), needsToUpperCase, locale);
|
final int code = needsToUpperCase ? StringUtils.toTitleCaseOfKeyCode(codeInSpec, locale)
|
||||||
|
: codeInSpec;
|
||||||
if (code == Constants.CODE_UNSPECIFIED) {
|
if (code == Constants.CODE_UNSPECIFIED) {
|
||||||
// Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters
|
// Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters
|
||||||
// upper case representation ("SS").
|
// upper case representation ("SS").
|
||||||
|
@ -66,8 +67,9 @@ public final class MoreKeySpec {
|
||||||
mOutputText = mLabel;
|
mOutputText = mLabel;
|
||||||
} else {
|
} else {
|
||||||
mCode = code;
|
mCode = code;
|
||||||
mOutputText = StringUtils.toUpperCaseOfStringForLocale(
|
final String outputText = KeySpecParser.getOutputText(moreKeySpec);
|
||||||
KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale);
|
mOutputText = needsToUpperCase
|
||||||
|
? StringUtils.toTitleCaseOfKeyLabel(outputText, locale) : outputText;
|
||||||
}
|
}
|
||||||
mIconId = KeySpecParser.getIconId(moreKeySpec);
|
mIconId = KeySpecParser.getIconId(moreKeySpec);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,7 @@ abstract class ExpectedKeyOutput {
|
||||||
final String codeString = StringUtils.newSingleCodePointString(mCode);
|
final String codeString = StringUtils.newSingleCodePointString(mCode);
|
||||||
// A letter may have an upper case counterpart that consists of multiple code
|
// A letter may have an upper case counterpart that consists of multiple code
|
||||||
// points, for instance the upper case of "ß" is "SS".
|
// points, for instance the upper case of "ß" is "SS".
|
||||||
return newInstance(StringUtils.toUpperCaseOfStringForLocale(
|
return newInstance(StringUtils.toTitleCaseOfKeyLabel(codeString, locale));
|
||||||
codeString, true /* needsToUpperCase */, locale));
|
|
||||||
}
|
}
|
||||||
// A special negative value has no upper case.
|
// A special negative value has no upper case.
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -135,8 +135,7 @@ public abstract class ExpectedKeyVisual {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ExpectedKeyVisual toUpperCase(final Locale locale) {
|
ExpectedKeyVisual toUpperCase(final Locale locale) {
|
||||||
return new Label(StringUtils.toUpperCaseOfStringForLocale(
|
return new Label(StringUtils.toTitleCaseOfKeyLabel(mLabel, locale));
|
||||||
mLabel, true /* needsToUpperCase */, locale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,17 +30,16 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
private static final Locale TURKEY = new Locale("tr", "TR");
|
private static final Locale TURKEY = new Locale("tr", "TR");
|
||||||
private static final Locale GREECE = new Locale("el", "GR");
|
private static final Locale GREECE = new Locale("el", "GR");
|
||||||
|
|
||||||
private static void assert_toUpperCaseOfStringForLocale(final Locale locale,
|
private static void assert_toTitleCaseOfKeyLabel(final Locale locale,
|
||||||
final String lowerCase, final String expected) {
|
final String lowerCase, final String expected) {
|
||||||
assertEquals(lowerCase + " in " + locale, expected,
|
assertEquals(lowerCase + " in " + locale, expected,
|
||||||
StringUtils.toUpperCaseOfStringForLocale(
|
StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale));
|
||||||
lowerCase, true /* needsToUpperCase */, locale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test_toUpperCaseOfStringForLocale() {
|
public void test_toTitleCaseOfKeyLabel() {
|
||||||
assert_toUpperCaseOfStringForLocale(US, null, null);
|
assert_toTitleCaseOfKeyLabel(US, null, null);
|
||||||
assert_toUpperCaseOfStringForLocale(US, "", "");
|
assert_toTitleCaseOfKeyLabel(US, "", "");
|
||||||
assert_toUpperCaseOfStringForLocale(US, "aeiou", "AEIOU");
|
assert_toTitleCaseOfKeyLabel(US, "aeiou", "AEIOU");
|
||||||
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
|
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
|
||||||
// U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE
|
// U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE
|
||||||
// U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX
|
// U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||||
|
@ -55,7 +54,7 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
// U+016A: "Ū" LATIN CAPITAL LETTER U WITH MACRON
|
// U+016A: "Ū" LATIN CAPITAL LETTER U WITH MACRON
|
||||||
// U+00D1: "Ñ" LATIN CAPITAL LETTER N WITH TILDE
|
// U+00D1: "Ñ" LATIN CAPITAL LETTER N WITH TILDE
|
||||||
// U+00C7: "Ç" LATIN CAPITAL LETTER C WITH CEDILLA
|
// U+00C7: "Ç" LATIN CAPITAL LETTER C WITH CEDILLA
|
||||||
assert_toUpperCaseOfStringForLocale(US,
|
assert_toTitleCaseOfKeyLabel(US,
|
||||||
"\u00E0\u00E8\u00EE\u00F6\u016B\u00F1\u00E7",
|
"\u00E0\u00E8\u00EE\u00F6\u016B\u00F1\u00E7",
|
||||||
"\u00C0\u00C8\u00CE\u00D6\u016A\u00D1\u00C7");
|
"\u00C0\u00C8\u00CE\u00D6\u016A\u00D1\u00C7");
|
||||||
// U+00DF: "ß" LATIN SMALL LETTER SHARP S
|
// U+00DF: "ß" LATIN SMALL LETTER SHARP S
|
||||||
|
@ -63,7 +62,7 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
// U+0161: "š" LATIN SMALL LETTER S WITH CARON
|
// U+0161: "š" LATIN SMALL LETTER S WITH CARON
|
||||||
// U+015A: "Ś" LATIN CAPITAL LETTER S WITH ACUTE
|
// U+015A: "Ś" LATIN CAPITAL LETTER S WITH ACUTE
|
||||||
// U+0160: "Š" LATIN CAPITAL LETTER S WITH CARONZ
|
// U+0160: "Š" LATIN CAPITAL LETTER S WITH CARONZ
|
||||||
assert_toUpperCaseOfStringForLocale(GERMAN,
|
assert_toTitleCaseOfKeyLabel(GERMAN,
|
||||||
"\u00DF\u015B\u0161",
|
"\u00DF\u015B\u0161",
|
||||||
"SS\u015A\u0160");
|
"SS\u015A\u0160");
|
||||||
// U+0259: "ə" LATIN SMALL LETTER SCHWA
|
// U+0259: "ə" LATIN SMALL LETTER SCHWA
|
||||||
|
@ -72,13 +71,13 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
// U+018F: "Ə" LATIN SMALL LETTER SCHWA
|
// U+018F: "Ə" LATIN SMALL LETTER SCHWA
|
||||||
// U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
|
// U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
|
||||||
// U+0049: "I" LATIN SMALL LETTER I
|
// U+0049: "I" LATIN SMALL LETTER I
|
||||||
assert_toUpperCaseOfStringForLocale(TURKEY,
|
assert_toTitleCaseOfKeyLabel(TURKEY,
|
||||||
"\u0259\u0069\u0131",
|
"\u0259\u0069\u0131",
|
||||||
"\u018F\u0130\u0049");
|
"\u018F\u0130\u0049");
|
||||||
// U+03C3: "σ" GREEK SMALL LETTER SIGMA
|
// U+03C3: "σ" GREEK SMALL LETTER SIGMA
|
||||||
// U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA
|
// U+03C2: "ς" GREEK SMALL LETTER FINAL SIGMA
|
||||||
// U+03A3: "Σ" GREEK CAPITAL LETTER SIGMA
|
// U+03A3: "Σ" GREEK CAPITAL LETTER SIGMA
|
||||||
assert_toUpperCaseOfStringForLocale(GREECE,
|
assert_toTitleCaseOfKeyLabel(GREECE,
|
||||||
"\u03C3\u03C2",
|
"\u03C3\u03C2",
|
||||||
"\u03A3\u03A3");
|
"\u03A3\u03A3");
|
||||||
// U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
|
// U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
|
@ -95,7 +94,7 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
// U+038C: "Ό" GREEK CAPITAL LETTER OMICRON WITH TONOS
|
// U+038C: "Ό" GREEK CAPITAL LETTER OMICRON WITH TONOS
|
||||||
// U+038E: "Ύ" GREEK CAPITAL LETTER UPSILON WITH TONOS
|
// U+038E: "Ύ" GREEK CAPITAL LETTER UPSILON WITH TONOS
|
||||||
// U+038F: "Ώ" GREEK CAPITAL LETTER OMEGA WITH TONOS
|
// U+038F: "Ώ" GREEK CAPITAL LETTER OMEGA WITH TONOS
|
||||||
assert_toUpperCaseOfStringForLocale(GREECE,
|
assert_toTitleCaseOfKeyLabel(GREECE,
|
||||||
"\u03AC\u03AD\u03AE\u03AF\u03CC\u03CD\u03CE",
|
"\u03AC\u03AD\u03AE\u03AF\u03CC\u03CD\u03CE",
|
||||||
"\u0386\u0388\u0389\u038A\u038C\u038E\u038F");
|
"\u0386\u0388\u0389\u038A\u038C\u038E\u038F");
|
||||||
// U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
|
// U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
|
||||||
|
@ -108,42 +107,41 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
// U+03A5: "Υ" GREEK CAPITAL LETTER UPSILON
|
// U+03A5: "Υ" GREEK CAPITAL LETTER UPSILON
|
||||||
// U+0308: COMBINING DIAERESIS
|
// U+0308: COMBINING DIAERESIS
|
||||||
// U+0301: COMBINING GRAVE ACCENT
|
// U+0301: COMBINING GRAVE ACCENT
|
||||||
assert_toUpperCaseOfStringForLocale(GREECE,
|
assert_toTitleCaseOfKeyLabel(GREECE,
|
||||||
"\u03CA\u03CB\u0390\u03B0",
|
"\u03CA\u03CB\u0390\u03B0",
|
||||||
"\u03AA\u03AB\u0399\u0308\u0301\u03A5\u0308\u0301");
|
"\u03AA\u03AB\u0399\u0308\u0301\u03A5\u0308\u0301");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assert_toUpperCaseOfCodeForLocale(final Locale locale, final int lowerCase,
|
private static void assert_toTitleCaseOfKeyCode(final Locale locale, final int lowerCase,
|
||||||
final int expected) {
|
final int expected) {
|
||||||
assertEquals(lowerCase + " in " + locale, expected,
|
assertEquals(lowerCase + " in " + locale, expected,
|
||||||
StringUtils.toUpperCaseOfCodeForLocale(
|
StringUtils.toTitleCaseOfKeyCode(lowerCase, locale));
|
||||||
lowerCase, true /* needsToUpperCase */, locale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test_toUpperCaseOfCodeForLocale() {
|
public void test_toTitleCaseOfKeyCode() {
|
||||||
assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_ENTER, Constants.CODE_ENTER);
|
assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER);
|
||||||
assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_SPACE, Constants.CODE_SPACE);
|
assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE);
|
||||||
assert_toUpperCaseOfCodeForLocale(US, Constants.CODE_COMMA, Constants.CODE_COMMA);
|
assert_toTitleCaseOfKeyCode(US, Constants.CODE_COMMA, Constants.CODE_COMMA);
|
||||||
// U+0069: "i" LATIN SMALL LETTER I
|
// U+0069: "i" LATIN SMALL LETTER I
|
||||||
// U+0131: "ı" LATIN SMALL LETTER DOTLESS I
|
// U+0131: "ı" LATIN SMALL LETTER DOTLESS I
|
||||||
// U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
|
// U+0130: "İ" LATIN SMALL LETTER I WITH DOT ABOVE
|
||||||
// U+0049: "I" LATIN SMALL LETTER I
|
// U+0049: "I" LATIN SMALL LETTER I
|
||||||
assert_toUpperCaseOfCodeForLocale(US, 0x0069, 0x0049); // i -> I
|
assert_toTitleCaseOfKeyCode(US, 0x0069, 0x0049); // i -> I
|
||||||
assert_toUpperCaseOfCodeForLocale(US, 0x0131, 0x0049); // ı -> I
|
assert_toTitleCaseOfKeyCode(US, 0x0131, 0x0049); // ı -> I
|
||||||
assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0069, 0x0130); // i -> İ
|
assert_toTitleCaseOfKeyCode(TURKEY, 0x0069, 0x0130); // i -> İ
|
||||||
assert_toUpperCaseOfCodeForLocale(TURKEY, 0x0131, 0x0049); // ı -> I
|
assert_toTitleCaseOfKeyCode(TURKEY, 0x0131, 0x0049); // ı -> I
|
||||||
// U+00DF: "ß" LATIN SMALL LETTER SHARP S
|
// U+00DF: "ß" LATIN SMALL LETTER SHARP S
|
||||||
// The title case of "ß" is "SS".
|
// The title case of "ß" is "SS".
|
||||||
assert_toUpperCaseOfCodeForLocale(US, 0x00DF, Constants.CODE_UNSPECIFIED);
|
assert_toTitleCaseOfKeyCode(US, 0x00DF, Constants.CODE_UNSPECIFIED);
|
||||||
// U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
|
// U+03AC: "ά" GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
// U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS
|
// U+0386: "Ά" GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||||
assert_toUpperCaseOfCodeForLocale(GREECE, 0x03AC, 0x0386);
|
assert_toTitleCaseOfKeyCode(GREECE, 0x03AC, 0x0386);
|
||||||
// U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
|
// U+03CA: "ϊ" GREEK SMALL LETTER IOTA WITH DIALYTIKA
|
||||||
// U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
|
// U+03AA: "Ϊ" GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
|
||||||
assert_toUpperCaseOfCodeForLocale(GREECE, 0x03CA, 0x03AA);
|
assert_toTitleCaseOfKeyCode(GREECE, 0x03CA, 0x03AA);
|
||||||
// U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
|
// U+03B0: "ΰ" GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
|
||||||
// The title case of "ΰ" is "\u03A5\u0308\u0301".
|
// The title case of "ΰ" is "\u03A5\u0308\u0301".
|
||||||
assert_toUpperCaseOfCodeForLocale(GREECE, 0x03B0, Constants.CODE_UNSPECIFIED);
|
assert_toTitleCaseOfKeyCode(GREECE, 0x03B0, Constants.CODE_UNSPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assert_capitalizeFirstCodePoint(final Locale locale, final String text,
|
private static void assert_capitalizeFirstCodePoint(final Locale locale, final String text,
|
||||||
|
|
Loading…
Reference in New Issue