aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/StringUtils.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-01-18 05:39:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-01-18 05:39:18 +0000
commit5a6b4f953eb036c2d3e42316d0d62045686d2b30 (patch)
tree4b0362cd3beb5132105efa4f84f1dabb654d8f9c /java/src/com/android/inputmethod/latin/StringUtils.java
parent345ef6762700cdb0fca25aa54b22ef83aaaac0ab (diff)
parent96845ecff62ac5a1131ce3eb8e6a06d3298dd984 (diff)
downloadlatinime-5a6b4f953eb036c2d3e42316d0d62045686d2b30.tar.gz
latinime-5a6b4f953eb036c2d3e42316d0d62045686d2b30.tar.xz
latinime-5a6b4f953eb036c2d3e42316d0d62045686d2b30.zip
Merge "Insert into user dict in lower case if auto-caps (D2)"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/StringUtils.java')
-rw-r--r--java/src/com/android/inputmethod/latin/StringUtils.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java
index ddaa5ff5b..d00edbe92 100644
--- a/java/src/com/android/inputmethod/latin/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/StringUtils.java
@@ -103,6 +103,37 @@ public final class StringUtils {
}
}
+ /**
+ * Apply an auto-caps mode to a string.
+ *
+ * This intentionally does NOT apply manual caps mode. It only changes the capitalization if
+ * the mode is one of the auto-caps modes.
+ * @param s The string to capitalize.
+ * @param capitalizeMode The mode in which to capitalize.
+ * @param locale The locale for capitalizing.
+ * @return The capitalized string.
+ */
+ public static String applyAutoCapsMode(final String s, final int capitalizeMode,
+ final Locale locale) {
+ if (WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == capitalizeMode) {
+ return s.toUpperCase(locale);
+ } else if (WordComposer.CAPS_MODE_AUTO_SHIFTED == capitalizeMode) {
+ return toTitleCase(s, locale);
+ } else {
+ return s;
+ }
+ }
+
+ /**
+ * Return whether a constant represents an auto-caps mode (either auto-shift or auto-shift-lock)
+ * @param mode The mode to test for
+ * @return true if this represents an auto-caps mode, false otherwise
+ */
+ public static boolean isAutoCapsMode(final int mode) {
+ return WordComposer.CAPS_MODE_AUTO_SHIFTED == mode
+ || WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == mode;
+ }
+
public static String toTitleCase(final String s, final Locale locale) {
if (s.length() <= 1) {
// TODO: is this really correct? Shouldn't this be s.toUpperCase()?