From 35dc8cf223f1e9c8939092139f7acba5c06a1ded Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 13 Sep 2012 19:07:15 +0900 Subject: [PATCH] Replace immediate values with named constants for characters (A6) Change-Id: I6248f9f3ff99003ab62be22eac673df0f7f5c015 --- .../android/inputmethod/keyboard/Keyboard.java | 2 ++ .../android/inputmethod/latin/StringUtils.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 261d1eba7..b7c7f415d 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -57,6 +57,8 @@ public class Keyboard { public static final int CODE_DASH = '-'; public static final int CODE_SINGLE_QUOTE = '\''; public static final int CODE_DOUBLE_QUOTE = '"'; + public static final int CODE_QUESTION_MARK = '?'; + public static final int CODE_EXCLAMATION_MARK = '!'; // TODO: Check how this should work for right-to-left languages. It seems to stand // that for rtl languages, a closing parenthesis is a left parenthesis. Is this // managed by the font? Or is it a different char? diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java index e38983fbd..8696a5caf 100644 --- a/java/src/com/android/inputmethod/latin/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -18,6 +18,8 @@ package com.android.inputmethod.latin; import android.text.TextUtils; +import com.android.inputmethod.keyboard.Keyboard; // For character constants + import java.util.ArrayList; import java.util.Locale; @@ -246,7 +248,8 @@ public final class StringUtils { int i; for (i = cs.length(); i > 0; i--) { final char c = cs.charAt(i - 1); - if (c != '"' && c != '\'' && Character.getType(c) != Character.START_PUNCTUATION) { + if (c != Keyboard.CODE_DOUBLE_QUOTE && c != Keyboard.CODE_SINGLE_QUOTE + && Character.getType(c) != Character.START_PUNCTUATION) { break; } } @@ -294,14 +297,16 @@ public final class StringUtils { // (note that American rules and British rules have nothing to do with en_US and en_GB, // as both rules are used in both countries - it's merely a name for the set of rules) final char c = cs.charAt(j - 1); - if (c != '"' && c != '\'' && Character.getType(c) != Character.END_PUNCTUATION) { + if (c != Keyboard.CODE_DOUBLE_QUOTE && c != Keyboard.CODE_SINGLE_QUOTE + && Character.getType(c) != Character.END_PUNCTUATION) { break; } } if (j <= 0) return TextUtils.CAP_MODE_CHARACTERS & reqModes; char c = cs.charAt(j - 1); - if (c == '.' || c == '?' || c == '!') { + if (c == Keyboard.CODE_PERIOD || c == Keyboard.CODE_QUESTION_MARK + || c == Keyboard.CODE_EXCLAMATION_MARK) { // Here we found a marker for sentence end (we consider these to be one of // either . or ? or ! only). So this is probably the end of a sentence, but if we // found a period, we still want to check the case where this is a abbreviation @@ -314,10 +319,10 @@ public final class StringUtils { // whatever the reason. In the example "in the U.S..", the last period is a full // stop following the abbreviation period, and we should capitalize but we don't. // Likewise, "I don't know... " should capitalize, but fails to do so. - if (c == '.') { + if (c == Keyboard.CODE_PERIOD) { for (int k = j - 2; k >= 0; k--) { c = cs.charAt(k); - if (c == '.') { + if (c == Keyboard.CODE_PERIOD) { return TextUtils.CAP_MODE_CHARACTERS & reqModes; } if (!Character.isLetter(c)) {