aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Utils.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-02-01 22:56:54 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-02-01 22:56:54 -0800
commit8ca325f437a4dd6484e14ac66415b792195dbd40 (patch)
treec8f5f7639903bd26de8f17ca11db20f058dee4c5 /java/src/com/android/inputmethod/latin/Utils.java
parent51fd1632f59bd9aaeb5c98ff031f1618e8c31c59 (diff)
parente01d272603f3643ce613e61dd3204379f4f4fb73 (diff)
downloadlatinime-8ca325f437a4dd6484e14ac66415b792195dbd40.tar.gz
latinime-8ca325f437a4dd6484e14ac66415b792195dbd40.tar.xz
latinime-8ca325f437a4dd6484e14ac66415b792195dbd40.zip
Merge "Make KeySpecParser and CSV parser code point aware"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index d1b808fc8..7b9e4e23d 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -800,6 +800,13 @@ public class Utils {
}
}
+ public static int codePointCount(String text) {
+ if (TextUtils.isEmpty(text)) return 0;
+ return text.codePointCount(0, text.length());
+ }
+
+ // TODO: Move these methods to KeySpecParser.
+
public static int getResourceId(Resources res, String name, int packageNameResId) {
String packageName = res.getResourcePackageName(packageNameResId);
int resId = res.getIdentifier(name, null, packageName);
@@ -858,13 +865,15 @@ public class Utils {
return size;
}
+ private static int COMMA = ',';
+
public static String[] parseCsvString(String rawText, Resources res, int packageNameResId) {
final String text = resolveStringResource(rawText, res, packageNameResId);
final int size = text.length();
if (size == 0) {
return null;
}
- if (size == 1) {
+ if (codePointCount(text) == 1) {
return new String[] { text };
}
@@ -873,7 +882,7 @@ public class Utils {
int start = 0;
for (int pos = 0; pos < size; pos++) {
final char c = text.charAt(pos);
- if (c == ',') {
+ if (c == COMMA) {
if (list == null) {
list = new ArrayList<String>();
}
@@ -883,17 +892,21 @@ public class Utils {
list.add(sb.toString());
sb.setLength(0);
}
+ // Skip comma
start = pos + 1;
continue;
- } else if (c == ESCAPE_CHAR) {
+ }
+ // Skip escaped sequence.
+ if (c == ESCAPE_CHAR) {
if (start == pos) {
- // Skip escape character at the beginning of the value.
+ // Skip escaping comma at the beginning of the text.
start++;
pos++;
} else {
if (start < pos && sb.length() == 0) {
- sb.append(text.subSequence(start, pos));
+ sb.append(text.substring(start, pos));
}
+ // Skip comma
pos++;
if (pos < size) {
sb.append(text.charAt(pos));