diff options
author | 2013-01-16 22:07:43 +0900 | |
---|---|---|
committer | 2013-01-17 20:38:52 +0900 | |
commit | 96845ecff62ac5a1131ce3eb8e6a06d3298dd984 (patch) | |
tree | 9ac9ae7ae3459cf3119b5604723f0362f50865ee /java/src/com/android/inputmethod/latin/StringUtils.java | |
parent | c665cbee7f136ea3cf334262f8dc1e7621f2004f (diff) | |
download | latinime-96845ecff62ac5a1131ce3eb8e6a06d3298dd984.tar.gz latinime-96845ecff62ac5a1131ce3eb8e6a06d3298dd984.tar.xz latinime-96845ecff62ac5a1131ce3eb8e6a06d3298dd984.zip |
Insert into user dict in lower case if auto-caps (D2)
Also recapitalize afterwards if the word has been changed.
Bug: 7972124
Change-Id: I9306580bb4ed0ffa80cc4559ce1abcd2034d1905
Diffstat (limited to 'java/src/com/android/inputmethod/latin/StringUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/StringUtils.java | 31 |
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()? |