am 2334bf6d: Merge "Fix a bug specific to German capitalization."

* commit '2334bf6d8c83e26b7932fbe8e195ab3429d62a04':
  Fix a bug specific to German capitalization.
main
Jean Chalard 2014-01-16 17:51:56 -08:00 committed by Android Git Automerger
commit 1f2b8564e6
4 changed files with 33 additions and 1 deletions

View File

@ -183,6 +183,7 @@ public final class Constants {
public static final int CODE_TAB = '\t'; public static final int CODE_TAB = '\t';
public static final int CODE_SPACE = ' '; public static final int CODE_SPACE = ' ';
public static final int CODE_PERIOD = '.'; public static final int CODE_PERIOD = '.';
public static final int CODE_COMMA = ',';
public static final int CODE_ARMENIAN_PERIOD = 0x0589; public static final int CODE_ARMENIAN_PERIOD = 0x0589;
public static final int CODE_DASH = '-'; public static final int CODE_DASH = '-';
public static final int CODE_SINGLE_QUOTE = '\''; public static final int CODE_SINGLE_QUOTE = '\'';

View File

@ -41,6 +41,7 @@ public final class SpacingAndPunctuations {
public final String mSentenceSeparatorAndSpace; public final String mSentenceSeparatorAndSpace;
public final boolean mCurrentLanguageHasSpaces; public final boolean mCurrentLanguageHasSpaces;
public final boolean mUsesAmericanTypography; public final boolean mUsesAmericanTypography;
public final boolean mUsesGermanRules;
public SpacingAndPunctuations(final Resources res) { public SpacingAndPunctuations(final Resources res) {
mSymbolsPrecededBySpace = mSymbolsPrecededBySpace =
@ -62,8 +63,9 @@ public final class SpacingAndPunctuations {
mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces); mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces);
final Locale locale = res.getConfiguration().locale; final Locale locale = res.getConfiguration().locale;
// Heuristic: we use American Typography rules because it's the most common rules for all // Heuristic: we use American Typography rules because it's the most common rules for all
// English variants. // English variants. German rules (not "German typography") also have small gotchas.
mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage()); mUsesAmericanTypography = Locale.ENGLISH.getLanguage().equals(locale.getLanguage());
mUsesGermanRules = Locale.GERMAN.getLanguage().equals(locale.getLanguage());
} }
// Helper functions to create member values. // Helper functions to create member values.

View File

@ -139,6 +139,20 @@ public final class CapsModeUtils {
j--; j--;
} }
if (j <= 0 || Character.isWhitespace(prevChar)) { if (j <= 0 || Character.isWhitespace(prevChar)) {
if (spacingAndPunctuations.mUsesGermanRules) {
// In German typography rules, there is a specific case that the first character
// of a new line should not be capitalized if the previous line ends in a comma.
boolean hasNewLine = false;
while (--j >= 0 && Character.isWhitespace(prevChar)) {
if (Constants.CODE_ENTER == prevChar) {
hasNewLine = true;
}
prevChar = cs.charAt(j);
}
if (Constants.CODE_COMMA == prevChar && hasNewLine) {
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & reqModes;
}
}
// There are only spacing chars between the start of the paragraph and the cursor, // There are only spacing chars between the start of the paragraph and the cursor,
// defined as a isWhitespace() char that is neither a isSpaceChar() nor a tab. Both // defined as a isWhitespace() char that is neither a isSpaceChar() nor a tab. Both
// MODE_WORDS and MODE_SENTENCES should be active. // MODE_WORDS and MODE_SENTENCES should be active.

View File

@ -94,5 +94,20 @@ public class CapsModeUtilsTests extends AndroidTestCase {
allPathsForCaps("\"Word.\" ", c | w, sp, false); allPathsForCaps("\"Word.\" ", c | w, sp, false);
allPathsForCaps("\"Word\". ", c | w | s, sp, false); allPathsForCaps("\"Word\". ", c | w | s, sp, false);
allPathsForCaps("\"Word\" ", c | w, sp, false); allPathsForCaps("\"Word\" ", c | w, sp, false);
// Test special case for German. German does not capitalize at the start of a
// line when the previous line starts with a comma. It does in other cases.
sp = job.runInLocale(res, Locale.GERMAN);
allPathsForCaps("Liebe Sara,\n", c | w, sp, false);
allPathsForCaps("Liebe Sara,\n", c | w, sp, true);
allPathsForCaps("Liebe Sara, \n ", c | w, sp, false);
allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false);
sp = job.runInLocale(res, Locale.ENGLISH);
allPathsForCaps("Liebe Sara,\n", c | w | s, sp, false);
allPathsForCaps("Liebe Sara,\n", c | w | s, sp, true);
allPathsForCaps("Liebe Sara, \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara \n ", c | w | s, sp, false);
allPathsForCaps("Liebe Sara.\n ", c | w | s, sp, false);
} }
} }