am e5db4c81: am e8db06fc: Merge "Replace immediate values with named constants for characters (A6)" into jb-mr1-dev

* commit 'e5db4c815d49ad2f99580be9fa9a9599feb8ac8e':
  Replace immediate values with named constants for characters (A6)
main
Jean Chalard 2012-09-14 10:31:04 -07:00 committed by Android Git Automerger
commit a0f88a628e
2 changed files with 12 additions and 5 deletions

View File

@ -57,6 +57,8 @@ public class Keyboard {
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 = '\'';
public static final int CODE_DOUBLE_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 // 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 // that for rtl languages, a closing parenthesis is a left parenthesis. Is this
// managed by the font? Or is it a different char? // managed by the font? Or is it a different char?

View File

@ -18,6 +18,8 @@ package com.android.inputmethod.latin;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.inputmethod.keyboard.Keyboard; // For character constants
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
@ -246,7 +248,8 @@ public final class StringUtils {
int i; int i;
for (i = cs.length(); i > 0; i--) { for (i = cs.length(); i > 0; i--) {
final char c = cs.charAt(i - 1); 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; 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, // (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) // 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); 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; break;
} }
} }
if (j <= 0) return TextUtils.CAP_MODE_CHARACTERS & reqModes; if (j <= 0) return TextUtils.CAP_MODE_CHARACTERS & reqModes;
char c = cs.charAt(j - 1); 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 // 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 // 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 // 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 // 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. // 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. // 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--) { for (int k = j - 2; k >= 0; k--) {
c = cs.charAt(k); c = cs.charAt(k);
if (c == '.') { if (c == Keyboard.CODE_PERIOD) {
return TextUtils.CAP_MODE_CHARACTERS & reqModes; return TextUtils.CAP_MODE_CHARACTERS & reqModes;
} }
if (!Character.isLetter(c)) { if (!Character.isLetter(c)) {