Move some methods to StringUtils

Change-Id: I29d87fdd65ec879d1c0bdf7e7792a677687c1693
This commit is contained in:
Tadashi G. Takaoka 2014-01-31 14:20:15 +09:00
parent 776d46a771
commit 639bf62e4f
4 changed files with 26 additions and 26 deletions

View File

@ -331,16 +331,16 @@ public class Key implements Comparable<Key> {
// code point nor as a surrogate pair.
mLabel = new StringBuilder().appendCodePoint(code).toString();
} else {
mLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
mLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
R.styleable.Keyboard_Key_keyLabel), needsToUpperCase, locale);
}
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
mHintLabel = null;
} else {
mHintLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
mHintLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
R.styleable.Keyboard_Key_keyHintLabel), needsToUpperCase, locale);
}
String outputText = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
String outputText = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
R.styleable.Keyboard_Key_keyOutputText), needsToUpperCase, locale);
// Choose the first letter of the label as primary code if not specified.
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
@ -367,9 +367,9 @@ public class Key implements Comparable<Key> {
mCode = CODE_OUTPUT_TEXT;
}
} else {
mCode = KeySpecParser.toUpperCaseOfCodeForLocale(code, needsToUpperCase, locale);
mCode = StringUtils.toUpperCaseOfCodeForLocale(code, needsToUpperCase, locale);
}
final int altCode = KeySpecParser.toUpperCaseOfCodeForLocale(
final int altCode = StringUtils.toUpperCaseOfCodeForLocale(
KeySpecParser.parseCode(style.getString(keyAttr,
R.styleable.Keyboard_Key_altCode), params.mCodesSet, CODE_UNSPECIFIED),
needsToUpperCase, locale);

View File

@ -21,14 +21,12 @@ import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
import android.text.TextUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
/**
* The string parser of more keys specification.
@ -482,20 +480,4 @@ public final class KeySpecParser {
}
return value;
}
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,
final Locale locale) {
if (!Constants.isLetterCode(code) || !needsToUpperCase) return code;
final String text = StringUtils.newSingleCodePointString(code);
final String casedText = KeySpecParser.toUpperCaseOfStringForLocale(
text, needsToUpperCase, locale);
return StringUtils.codePointCount(casedText) == 1
? casedText.codePointAt(0) : CODE_UNSPECIFIED;
}
public static String toUpperCaseOfStringForLocale(final String text,
final boolean needsToUpperCase, final Locale locale) {
if (text == null || !needsToUpperCase) return text;
return text.toUpperCase(locale);
}
}

View File

@ -31,9 +31,9 @@ public final class MoreKeySpec {
public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale,
final KeyboardCodesSet codesSet) {
mLabel = KeySpecParser.toUpperCaseOfStringForLocale(
mLabel = StringUtils.toUpperCaseOfStringForLocale(
KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale);
final int code = KeySpecParser.toUpperCaseOfCodeForLocale(
final int code = StringUtils.toUpperCaseOfCodeForLocale(
KeySpecParser.getCode(moreKeySpec, codesSet), needsToUpperCase, locale);
if (code == Constants.CODE_UNSPECIFIED) {
// Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters
@ -42,7 +42,7 @@ public final class MoreKeySpec {
mOutputText = mLabel;
} else {
mCode = code;
mOutputText = KeySpecParser.toUpperCaseOfStringForLocale(
mOutputText = StringUtils.toUpperCaseOfStringForLocale(
KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale);
}
mIconId = KeySpecParser.getIconId(moreKeySpec);

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.latin.utils;
import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
import android.text.TextUtils;
import com.android.inputmethod.annotations.UsedForTesting;
@ -471,4 +473,20 @@ public final class StringUtils {
}
return bytes;
}
public static String toUpperCaseOfStringForLocale(final String text,
final boolean needsToUpperCase, final Locale locale) {
if (text == null || !needsToUpperCase) return text;
return text.toUpperCase(locale);
}
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,
final Locale locale) {
if (!Constants.isLetterCode(code) || !needsToUpperCase) return code;
final String text = newSingleCodePointString(code);
final String casedText = toUpperCaseOfStringForLocale(
text, needsToUpperCase, locale);
return codePointCount(casedText) == 1
? casedText.codePointAt(0) : CODE_UNSPECIFIED;
}
}