Loading java/src/com/android/inputmethod/latin/Constants.java +1 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ public final class Constants { public static final int CODE_TAB = '\t'; public static final int CODE_SPACE = ' '; 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_DASH = '-'; public static final int CODE_SINGLE_QUOTE = '\''; Loading java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java +3 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ public final class SpacingAndPunctuations { public final String mSentenceSeparatorAndSpace; public final boolean mCurrentLanguageHasSpaces; public final boolean mUsesAmericanTypography; public final boolean mUsesGermanRules; public SpacingAndPunctuations(final Resources res) { mSymbolsPrecededBySpace = Loading @@ -62,8 +63,9 @@ public final class SpacingAndPunctuations { mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces); final Locale locale = res.getConfiguration().locale; // 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()); mUsesGermanRules = Locale.GERMAN.getLanguage().equals(locale.getLanguage()); } // Helper functions to create member values. Loading java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java +14 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,20 @@ public final class CapsModeUtils { j--; } 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, // defined as a isWhitespace() char that is neither a isSpaceChar() nor a tab. Both // MODE_WORDS and MODE_SENTENCES should be active. Loading tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java +15 −0 Original line number Diff line number Diff line Loading @@ -94,5 +94,20 @@ public class CapsModeUtilsTests extends AndroidTestCase { allPathsForCaps("\"Word.\" ", c | w, sp, false); allPathsForCaps("\"Word\". ", c | w | s, 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
java/src/com/android/inputmethod/latin/Constants.java +1 −0 Original line number Diff line number Diff line Loading @@ -183,6 +183,7 @@ public final class Constants { public static final int CODE_TAB = '\t'; public static final int CODE_SPACE = ' '; 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_DASH = '-'; public static final int CODE_SINGLE_QUOTE = '\''; Loading
java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java +3 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ public final class SpacingAndPunctuations { public final String mSentenceSeparatorAndSpace; public final boolean mCurrentLanguageHasSpaces; public final boolean mUsesAmericanTypography; public final boolean mUsesGermanRules; public SpacingAndPunctuations(final Resources res) { mSymbolsPrecededBySpace = Loading @@ -62,8 +63,9 @@ public final class SpacingAndPunctuations { mCurrentLanguageHasSpaces = res.getBoolean(R.bool.current_language_has_spaces); final Locale locale = res.getConfiguration().locale; // 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()); mUsesGermanRules = Locale.GERMAN.getLanguage().equals(locale.getLanguage()); } // Helper functions to create member values. Loading
java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java +14 −0 Original line number Diff line number Diff line Loading @@ -139,6 +139,20 @@ public final class CapsModeUtils { j--; } 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, // defined as a isWhitespace() char that is neither a isSpaceChar() nor a tab. Both // MODE_WORDS and MODE_SENTENCES should be active. Loading
tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java +15 −0 Original line number Diff line number Diff line Loading @@ -94,5 +94,20 @@ public class CapsModeUtilsTests extends AndroidTestCase { allPathsForCaps("\"Word.\" ", c | w, sp, false); allPathsForCaps("\"Word\". ", c | w | s, 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); } }