Fix a bug specific to German capitalization.
Bug: 9663105 Change-Id: Ib68ee4edb135e96dfca229c1ccce308e7e638bddmain
parent
cdeeadf5ca
commit
60afa7000f
|
@ -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 = '\'';
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue