aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-01-09 17:21:06 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-01-09 18:19:17 +0900
commit0a75cf51afbdc79ccb2c6eabaf06a0aa26263af5 (patch)
tree9991295c6f4fc9bda3d224e0fde923830a874e9d
parent860c3b8e8cc65e2a2b26b4da0356b5bcff6450e6 (diff)
downloadlatinime-0a75cf51afbdc79ccb2c6eabaf06a0aa26263af5.tar.gz
latinime-0a75cf51afbdc79ccb2c6eabaf06a0aa26263af5.tar.xz
latinime-0a75cf51afbdc79ccb2c6eabaf06a0aa26263af5.zip
Passing SpacingAndPunctuations to CapsModeUtils.getCapsMode
Change-Id: I0b06e8cc75a403f7061864c5b7f3f6a2cacd60eb
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java3
-rw-r--r--java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java14
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java94
3 files changed, 59 insertions, 52 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 7cf64a3bc..22377e0b0 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -35,7 +35,6 @@ import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TextRange;
import com.android.inputmethod.research.ResearchLogger;
-import java.util.Locale;
import java.util.regex.Pattern;
/**
@@ -302,7 +301,7 @@ public final class RichInputConnection {
// This never calls InputConnection#getCapsMode - in fact, it's a static method that
// never blocks or initiates IPC.
return CapsModeUtils.getCapsMode(mCommittedTextBeforeComposingText, inputType,
- settingsValues, hasSpaceBefore);
+ settingsValues.mSpacingAndPunctuations, hasSpaceBefore);
}
public int getCodePointBeforeCursor() {
diff --git a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
index c7416727a..057e332e9 100644
--- a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
@@ -21,7 +21,7 @@ import android.text.TextUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.WordComposer;
-import com.android.inputmethod.latin.settings.SettingsValues;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import java.util.Locale;
@@ -74,7 +74,7 @@ public final class CapsModeUtils {
* @param reqModes The modes to be checked: may be any combination of
* {@link TextUtils#CAP_MODE_CHARACTERS}, {@link TextUtils#CAP_MODE_WORDS}, and
* {@link TextUtils#CAP_MODE_SENTENCES}.
- * @param settingsValues The current settings values.
+ * @param spacingAndPunctuations The current spacing and punctuations settings.
* @param hasSpaceBefore Whether we should consider there is a space inserted at the end of cs
*
* @return Returns the actual capitalization modes that can be in effect
@@ -83,7 +83,7 @@ public final class CapsModeUtils {
* {@link TextUtils#CAP_MODE_SENTENCES}.
*/
public static int getCapsMode(final CharSequence cs, final int reqModes,
- final SettingsValues settingsValues, final boolean hasSpaceBefore) {
+ final SpacingAndPunctuations spacingAndPunctuations, final boolean hasSpaceBefore) {
// Quick description of what we want to do:
// CAP_MODE_CHARACTERS is always on.
// CAP_MODE_WORDS is on if there is some whitespace before the cursor.
@@ -167,7 +167,7 @@ public final class CapsModeUtils {
// No other language has such a rule as far as I know, instead putting inside the quotation
// mark as the exact thing quoted and handling the surrounding punctuation independently,
// e.g. <<Did he say, "let's go home"?>>
- if (settingsValues.mSpacingAndPunctuations.mUsesAmericanTypography) {
+ if (spacingAndPunctuations.mUsesAmericanTypography) {
for (; j > 0; j--) {
// Here we look to go over any closing punctuation. This is because in dominant
// variants of English, the final period is placed within double quotes and maybe
@@ -190,7 +190,7 @@ public final class CapsModeUtils {
if (c == Constants.CODE_QUESTION_MARK || c == Constants.CODE_EXCLAMATION_MARK) {
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_SENTENCES) & reqModes;
}
- if (!settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c) || j <= 0) {
+ if (!spacingAndPunctuations.isSentenceSeparator(c) || j <= 0) {
return (TextUtils.CAP_MODE_CHARACTERS | TextUtils.CAP_MODE_WORDS) & reqModes;
}
@@ -240,7 +240,7 @@ public final class CapsModeUtils {
case WORD:
if (Character.isLetter(c)) {
state = WORD;
- } else if (settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c)) {
+ } else if (spacingAndPunctuations.isSentenceSeparator(c)) {
state = PERIOD;
} else {
return caps;
@@ -256,7 +256,7 @@ public final class CapsModeUtils {
case LETTER:
if (Character.isLetter(c)) {
state = LETTER;
- } else if (settingsValues.mSpacingAndPunctuations.isSentenceSeparator(c)) {
+ } else if (spacingAndPunctuations.isSentenceSeparator(c)) {
state = PERIOD;
} else {
return noCaps;
diff --git a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
index 1fd5c989a..40a103b84 100644
--- a/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/CapsModeUtilsTests.java
@@ -16,75 +16,83 @@
package com.android.inputmethod.latin.utils;
-import com.android.inputmethod.latin.settings.SettingsValues;
-
+import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
+
import java.util.Locale;
@SmallTest
public class CapsModeUtilsTests extends AndroidTestCase {
private static void onePathForCaps(final CharSequence cs, final int expectedResult,
- final int mask, final SettingsValues sv, final boolean hasSpaceBefore) {
- int oneTimeResult = expectedResult & mask;
+ final int mask, final SpacingAndPunctuations sp, final boolean hasSpaceBefore) {
+ final int oneTimeResult = expectedResult & mask;
assertEquals("After >" + cs + "<", oneTimeResult,
- CapsModeUtils.getCapsMode(cs, mask, sv, hasSpaceBefore));
+ CapsModeUtils.getCapsMode(cs, mask, sp, hasSpaceBefore));
}
private static void allPathsForCaps(final CharSequence cs, final int expectedResult,
- final SettingsValues sv, final boolean hasSpaceBefore) {
+ final SpacingAndPunctuations sp, final boolean hasSpaceBefore) {
final int c = TextUtils.CAP_MODE_CHARACTERS;
final int w = TextUtils.CAP_MODE_WORDS;
final int s = TextUtils.CAP_MODE_SENTENCES;
- onePathForCaps(cs, expectedResult, c | w | s, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w | s, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | s, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c | w, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, c, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, w, sv, hasSpaceBefore);
- onePathForCaps(cs, expectedResult, s, sv, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | w | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | s, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c | w, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, c, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, w, sp, hasSpaceBefore);
+ onePathForCaps(cs, expectedResult, s, sp, hasSpaceBefore);
}
public void testGetCapsMode() {
final int c = TextUtils.CAP_MODE_CHARACTERS;
final int w = TextUtils.CAP_MODE_WORDS;
final int s = TextUtils.CAP_MODE_SENTENCES;
- SettingsValues sv = SettingsValues.makeDummySettingsValuesForTest(Locale.ENGLISH);
- allPathsForCaps("", c | w | s, sv, false);
- allPathsForCaps("Word", c, sv, false);
- allPathsForCaps("Word.", c, sv, false);
- allPathsForCaps("Word ", c | w, sv, false);
- allPathsForCaps("Word. ", c | w | s, sv, false);
- allPathsForCaps("Word..", c, sv, false);
- allPathsForCaps("Word.. ", c | w | s, sv, false);
- allPathsForCaps("Word... ", c | w | s, sv, false);
- allPathsForCaps("Word ... ", c | w | s, sv, false);
- allPathsForCaps("Word . ", c | w, sv, false);
- allPathsForCaps("In the U.S ", c | w, sv, false);
- allPathsForCaps("In the U.S. ", c | w, sv, false);
- allPathsForCaps("Some stuff (e.g. ", c | w, sv, false);
- allPathsForCaps("In the U.S.. ", c | w | s, sv, false);
- allPathsForCaps("\"Word.\" ", c | w | s, sv, false);
- allPathsForCaps("\"Word\". ", c | w | s, sv, false);
- allPathsForCaps("\"Word\" ", c | w, sv, false);
+ final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {
+ @Override
+ protected SpacingAndPunctuations job(final Resources res) {
+ return new SpacingAndPunctuations(res);
+ }
+ };
+ final Resources res = getContext().getResources();
+ SpacingAndPunctuations sp = job.runInLocale(res, Locale.ENGLISH);
+ allPathsForCaps("", c | w | s, sp, false);
+ allPathsForCaps("Word", c, sp, false);
+ allPathsForCaps("Word.", c, sp, false);
+ allPathsForCaps("Word ", c | w, sp, false);
+ allPathsForCaps("Word. ", c | w | s, sp, false);
+ allPathsForCaps("Word..", c, sp, false);
+ allPathsForCaps("Word.. ", c | w | s, sp, false);
+ allPathsForCaps("Word... ", c | w | s, sp, false);
+ allPathsForCaps("Word ... ", c | w | s, sp, false);
+ allPathsForCaps("Word . ", c | w, sp, false);
+ allPathsForCaps("In the U.S ", c | w, sp, false);
+ allPathsForCaps("In the U.S. ", c | w, sp, false);
+ allPathsForCaps("Some stuff (e.g. ", c | w, sp, false);
+ allPathsForCaps("In the U.S.. ", c | w | s, sp, false);
+ allPathsForCaps("\"Word.\" ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\". ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\" ", c | w, sp, false);
// Test for phantom space
- allPathsForCaps("Word", c | w, sv, true);
- allPathsForCaps("Word.", c | w | s, sv, true);
+ allPathsForCaps("Word", c | w, sp, true);
+ allPathsForCaps("Word.", c | w | s, sp, true);
// Tests after some whitespace
- allPathsForCaps("Word\n", c | w | s, sv, false);
- allPathsForCaps("Word\n", c | w | s, sv, true);
- allPathsForCaps("Word\n ", c | w | s, sv, true);
- allPathsForCaps("Word.\n", c | w | s, sv, false);
- allPathsForCaps("Word.\n", c | w | s, sv, true);
- allPathsForCaps("Word.\n ", c | w | s, sv, true);
+ allPathsForCaps("Word\n", c | w | s, sp, false);
+ allPathsForCaps("Word\n", c | w | s, sp, true);
+ allPathsForCaps("Word\n ", c | w | s, sp, true);
+ allPathsForCaps("Word.\n", c | w | s, sp, false);
+ allPathsForCaps("Word.\n", c | w | s, sp, true);
+ allPathsForCaps("Word.\n ", c | w | s, sp, true);
- sv = SettingsValues.makeDummySettingsValuesForTest(Locale.FRENCH);
- allPathsForCaps("\"Word.\" ", c | w, sv, false);
- allPathsForCaps("\"Word\". ", c | w | s, sv, false);
- allPathsForCaps("\"Word\" ", c | w, sv, false);
+ sp = job.runInLocale(res, Locale.FRENCH);
+ allPathsForCaps("\"Word.\" ", c | w, sp, false);
+ allPathsForCaps("\"Word\". ", c | w | s, sp, false);
+ allPathsForCaps("\"Word\" ", c | w, sp, false);
}
}