am 99b93d17: Fix a bug where autocorrection status would be wrong.

* commit '99b93d17d53c2d587c45373831b327f7851ec0a8':
  Fix a bug where autocorrection status would be wrong.
This commit is contained in:
Jean Chalard 2013-04-10 01:58:42 -07:00 committed by Android Git Automerger
commit 2dd2e2d7df
9 changed files with 42 additions and 21 deletions

View File

@ -1460,7 +1460,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return "";
}
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
return StringUtils.capitalizeFirstCharacter(locale.getLanguage(), locale);
return StringUtils.capitalizeFirstCodePoint(locale.getLanguage(), locale);
}
// Get InputMethodSubtype's middle display name in its locale.

View File

@ -41,7 +41,7 @@ public final class CapsModeUtils {
if (WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == capitalizeMode) {
return s.toUpperCase(locale);
} else if (WordComposer.CAPS_MODE_AUTO_SHIFTED == capitalizeMode) {
return StringUtils.toTitleCase(s, locale);
return StringUtils.capitalizeFirstCodePoint(s, locale);
} else {
return s;
}

View File

@ -106,16 +106,17 @@ public final class StringUtils {
}
}
public static String capitalizeFirstCharacter(final String s, final Locale locale) {
public static String capitalizeFirstCodePoint(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)}.
// Please refer to the comment below in
// {@link #capitalizeFirstAndDowncaseRest(String,Locale)} as this has the same shortcomings
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 capitalizeFirstAndDowncaseRest(final String s, final Locale locale) {
if (s.length() <= 1) {
return s.toUpperCase(locale);
}

View File

@ -183,7 +183,7 @@ public final class SubtypeLocale {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
displayName = locale.getDisplayName(displayLocale);
}
return StringUtils.capitalizeFirstCharacter(displayName, displayLocale);
return StringUtils.capitalizeFirstCodePoint(displayName, displayLocale);
}
// InputMethodSubtype's display name in its locale.
@ -243,7 +243,7 @@ public final class SubtypeLocale {
}
}
};
return StringUtils.capitalizeFirstCharacter(
return StringUtils.capitalizeFirstCodePoint(
getSubtypeName.runInLocale(sResources, displayLocale), displayLocale);
}

View File

@ -394,7 +394,7 @@ public final class Suggest {
if (isAllUpperCase) {
sb.append(wordInfo.mWord.toUpperCase(locale));
} else if (isFirstCharCapitalized) {
sb.append(StringUtils.toTitleCase(wordInfo.mWord, locale));
sb.append(StringUtils.capitalizeFirstCodePoint(wordInfo.mWord, locale));
} else {
sb.append(wordInfo.mWord);
}

View File

@ -330,7 +330,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
} else if (StringUtils.CAPITALIZE_FIRST == capitalizeType) {
for (int i = 0; i < mSuggestions.size(); ++i) {
// Likewise
mSuggestions.set(i, StringUtils.toTitleCase(
mSuggestions.set(i, StringUtils.capitalizeFirstCodePoint(
mSuggestions.get(i).toString(), locale));
}
}

View File

@ -226,7 +226,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
// If the lower case version is not in the dictionary, it's still possible
// that we have an all-caps version of a word that needs to be capitalized
// according to the dictionary. E.g. "GERMANS" only exists in the dictionary as "Germans".
return dict.isValidWord(StringUtils.toTitleCase(lowerCaseText, mLocale));
return dict.isValidWord(StringUtils.capitalizeFirstAndDowncaseRest(lowerCaseText, mLocale));
}
// Note : this must be reentrant

View File

@ -113,7 +113,7 @@ public class SpacebarTextTests extends AndroidTestCase {
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
final String languageCode = StringUtils.capitalizeFirstCharacter(
final String languageCode = StringUtils.capitalizeFirstCodePoint(
locale.getLanguage(), locale);
if (SubtypeLocale.isNoLanguage(subtype)) {
assertEquals(subtypeName, "", spacebarText);

View File

@ -93,23 +93,43 @@ public class StringUtilsTests extends AndroidTestCase {
StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5"));
}
public void testToTitleCase() {
public void testCapitalizeFirstCodePoint() {
assertEquals("SSaa",
StringUtils.toTitleCase("ßaa", Locale.GERMAN));
StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN));
assertEquals("Aßa",
StringUtils.toTitleCase("aßa", Locale.GERMAN));
StringUtils.capitalizeFirstCodePoint("aßa", Locale.GERMAN));
assertEquals("Iab",
StringUtils.toTitleCase("iab", Locale.ENGLISH));
assertEquals("Camelcase",
StringUtils.toTitleCase("cAmElCaSe", Locale.ENGLISH));
StringUtils.capitalizeFirstCodePoint("iab", Locale.ENGLISH));
assertEquals("cAmElCaSe",
StringUtils.capitalizeFirstCodePoint("cAmElCaSe", Locale.ENGLISH));
assertEquals("İab",
StringUtils.toTitleCase("iab", new Locale("tr")));
StringUtils.capitalizeFirstCodePoint("iab", new Locale("tr")));
assertEquals("AİB",
StringUtils.capitalizeFirstCodePoint("AİB", new Locale("tr")));
assertEquals("A",
StringUtils.capitalizeFirstCodePoint("a", Locale.ENGLISH));
assertEquals("A",
StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH));
}
public void testCapitalizeFirstAndDowncaseRest() {
assertEquals("SSaa",
StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN));
assertEquals("Aßa",
StringUtils.capitalizeFirstAndDowncaseRest("aßa", Locale.GERMAN));
assertEquals("Iab",
StringUtils.capitalizeFirstAndDowncaseRest("iab", Locale.ENGLISH));
assertEquals("Camelcase",
StringUtils.capitalizeFirstAndDowncaseRest("cAmElCaSe", Locale.ENGLISH));
assertEquals("İab",
StringUtils.capitalizeFirstAndDowncaseRest("iab", new Locale("tr")));
assertEquals("Aib",
StringUtils.toTitleCase("AİB", new Locale("tr")));
StringUtils.capitalizeFirstAndDowncaseRest("AİB", new Locale("tr")));
assertEquals("A",
StringUtils.toTitleCase("a", Locale.ENGLISH));
StringUtils.capitalizeFirstAndDowncaseRest("a", Locale.ENGLISH));
assertEquals("A",
StringUtils.toTitleCase("A", Locale.ENGLISH));
StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH));
}
public void testGetCapitalizationType() {