aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Utils.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Utils.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java127
1 files changed, 0 insertions, 127 deletions
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 7b9e4e23d..3975dddeb 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -62,12 +62,6 @@ public class Utils {
private static boolean DBG = LatinImeLogger.sDBG;
private static boolean DBG_EDIT_DISTANCE = false;
- // Constants for resource name parsing.
- public static final char ESCAPE_CHAR = '\\';
- public static final char PREFIX_AT = '@';
- public static final char SUFFIX_SLASH = '/';
- private static final String PREFIX_STRING = PREFIX_AT + "string";
-
private Utils() {
// Intentional empty constructor for utility class.
}
@@ -804,125 +798,4 @@ public class Utils {
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);
- if (resId == 0) {
- throw new RuntimeException("Unknown resource: " + name);
- }
- return resId;
- }
-
- public static String resolveStringResource(String text, Resources res, int packageNameResId) {
- final int size = text.length();
- if (size < PREFIX_STRING.length()) {
- return text;
- }
-
- StringBuilder sb = null;
- for (int pos = 0; pos < size; pos++) {
- final char c = text.charAt(pos);
- if (c == PREFIX_AT && text.startsWith(PREFIX_STRING, pos)) {
- if (sb == null) {
- sb = new StringBuilder(text.substring(0, pos));
- }
- final int end = Utils.searchResourceNameEnd(text, pos + PREFIX_STRING.length());
- final String resName = text.substring(pos + 1, end);
- final int resId = getResourceId(res, resName, packageNameResId);
- sb.append(res.getString(resId));
- pos = end - 1;
- } else if (c == ESCAPE_CHAR) {
- pos++;
- if (sb != null) {
- sb.append(c);
- if (pos < size) {
- sb.append(text.charAt(pos));
- }
- }
- } else if (sb != null) {
- sb.append(c);
- }
- }
- return (sb == null) ? text : sb.toString();
- }
-
- private static int searchResourceNameEnd(String text, int start) {
- final int size = text.length();
- if (start >= size || text.charAt(start) != SUFFIX_SLASH) {
- throw new RuntimeException("Resource name not specified");
- }
- for (int pos = start + 1; pos < size; pos++) {
- final char c = text.charAt(pos);
- // String resource name should be consisted of [a-z_0-9].
- if ((c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) {
- continue;
- }
- return pos;
- }
- 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 (codePointCount(text) == 1) {
- return new String[] { text };
- }
-
- final StringBuilder sb = new StringBuilder();
- ArrayList<String> list = null;
- int start = 0;
- for (int pos = 0; pos < size; pos++) {
- final char c = text.charAt(pos);
- if (c == COMMA) {
- if (list == null) {
- list = new ArrayList<String>();
- }
- if (sb.length() == 0) {
- list.add(text.substring(start, pos));
- } else {
- list.add(sb.toString());
- sb.setLength(0);
- }
- // Skip comma
- start = pos + 1;
- continue;
- }
- // Skip escaped sequence.
- if (c == ESCAPE_CHAR) {
- if (start == pos) {
- // Skip escaping comma at the beginning of the text.
- start++;
- pos++;
- } else {
- if (start < pos && sb.length() == 0) {
- sb.append(text.substring(start, pos));
- }
- // Skip comma
- pos++;
- if (pos < size) {
- sb.append(text.charAt(pos));
- }
- }
- } else if (sb.length() > 0) {
- sb.append(c);
- }
- }
- if (list == null) {
- return new String[] {
- sb.length() > 0 ? sb.toString() : text.substring(start)
- };
- } else {
- list.add(sb.length() > 0 ? sb.toString() : text.substring(start));
- return list.toArray(new String[list.size()]);
- }
- }
}