am f5aa2fd5: am 10af4b6e: Merge "Separate StringUtils.capitalizeFirstCharacter"
* commit 'f5aa2fd5c868cae6e879858738a5eef4445aaca8': Separate StringUtils.capitalizeFirstCharactermain
commit
f0a4508ad5
|
@ -1460,7 +1460,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
||||||
return StringUtils.toTitleCase(locale.getLanguage(), locale);
|
return StringUtils.capitalizeFirstCharacter(locale.getLanguage(), locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get InputMethodSubtype's middle display name in its locale.
|
// Get InputMethodSubtype's middle display name in its locale.
|
||||||
|
|
|
@ -106,10 +106,18 @@ public final class StringUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String capitalizeFirstCharacter(final String s, final Locale locale) {
|
||||||
|
if (s.length() <= 1) {
|
||||||
|
return s.toUpperCase(locale);
|
||||||
|
}
|
||||||
|
// Please refer to the comment below in {@link #toTitleCase(String,Locale)}.
|
||||||
|
final int cutoff = s.offsetByCodePoints(0, 1);
|
||||||
|
return s.substring(0, cutoff).toUpperCase(locale) + s.substring(cutoff);
|
||||||
|
}
|
||||||
|
|
||||||
public static String toTitleCase(final String s, final Locale locale) {
|
public static String toTitleCase(final String s, final Locale locale) {
|
||||||
if (s.length() <= 1) {
|
if (s.length() <= 1) {
|
||||||
// TODO: is this really correct? Shouldn't this be s.toUpperCase()?
|
return s.toUpperCase(locale);
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
// TODO: fix the bugs below
|
// TODO: fix the bugs below
|
||||||
// - This does not work for Greek, because it returns upper case instead of title case.
|
// - This does not work for Greek, because it returns upper case instead of title case.
|
||||||
|
|
|
@ -183,7 +183,7 @@ public final class SubtypeLocale {
|
||||||
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
||||||
displayName = locale.getDisplayName(displayLocale);
|
displayName = locale.getDisplayName(displayLocale);
|
||||||
}
|
}
|
||||||
return StringUtils.toTitleCase(displayName, displayLocale);
|
return StringUtils.capitalizeFirstCharacter(displayName, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputMethodSubtype's display name in its locale.
|
// InputMethodSubtype's display name in its locale.
|
||||||
|
@ -243,7 +243,7 @@ public final class SubtypeLocale {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return StringUtils.toTitleCase(
|
return StringUtils.capitalizeFirstCharacter(
|
||||||
getSubtypeName.runInLocale(sResources, displayLocale), displayLocale);
|
getSubtypeName.runInLocale(sResources, displayLocale), displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,8 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
||||||
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
|
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
|
||||||
final String languageCode = StringUtils.toTitleCase(locale.getLanguage(), locale);
|
final String languageCode = StringUtils.capitalizeFirstCharacter(
|
||||||
|
locale.getLanguage(), locale);
|
||||||
if (SubtypeLocale.isNoLanguage(subtype)) {
|
if (SubtypeLocale.isNoLanguage(subtype)) {
|
||||||
assertEquals(subtypeName, "", spacebarText);
|
assertEquals(subtypeName, "", spacebarText);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -106,9 +106,7 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
StringUtils.toTitleCase("iab", new Locale("tr")));
|
StringUtils.toTitleCase("iab", new Locale("tr")));
|
||||||
assertEquals("Aib",
|
assertEquals("Aib",
|
||||||
StringUtils.toTitleCase("AİB", new Locale("tr")));
|
StringUtils.toTitleCase("AİB", new Locale("tr")));
|
||||||
// For one character, toTitleCase returns the string as is. Not sure what the motivation
|
assertEquals("A",
|
||||||
// is, but that's how it works now.
|
|
||||||
assertEquals("a",
|
|
||||||
StringUtils.toTitleCase("a", Locale.ENGLISH));
|
StringUtils.toTitleCase("a", Locale.ENGLISH));
|
||||||
assertEquals("A",
|
assertEquals("A",
|
||||||
StringUtils.toTitleCase("A", Locale.ENGLISH));
|
StringUtils.toTitleCase("A", Locale.ENGLISH));
|
||||||
|
|
Loading…
Reference in New Issue