diff options
author | 2012-12-04 16:11:18 +0900 | |
---|---|---|
committer | 2012-12-04 18:05:27 +0900 | |
commit | 95bfb8ac474d242f7abe83709df5c853a6d08619 (patch) | |
tree | ae527e436ef1ee2984904e07b6e06da5c89da73b /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | |
parent | 8918cb46f6587eecc5ba805b3421e07c24db5a13 (diff) | |
download | latinime-95bfb8ac474d242f7abe83709df5c853a6d08619.tar.gz latinime-95bfb8ac474d242f7abe83709df5c853a6d08619.tar.xz latinime-95bfb8ac474d242f7abe83709df5c853a6d08619.zip |
Fix wrong misspelling reports of fully capitalized words
Two flavors of words would be wrongly reported as misspelled
by the android spell checker when they are written in all
upper case letters:
- Words containing a quote or a dash or any other non-letter
- Words that need the first letter to be capitalized
Bug: 7659216
Change-Id: Ibc5d261945ffcbb8a858d4c73b7c62cef6671abf
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 49b98863f..2f146f86c 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -438,15 +438,23 @@ public final class AndroidSpellCheckerService extends SpellCheckerService if (!Character.isUpperCase(text.codePointAt(0))) return CAPITALIZE_NONE; final int len = text.length(); int capsCount = 1; + int letterCount = 1; for (int i = 1; i < len; i = text.offsetByCodePoints(i, 1)) { - if (1 != capsCount && i != capsCount) break; - if (Character.isUpperCase(text.codePointAt(i))) ++capsCount; + if (1 != capsCount && letterCount != capsCount) break; + final int codePoint = text.codePointAt(i); + if (Character.isUpperCase(codePoint)) { + ++capsCount; + ++letterCount; + } else if (Character.isLetter(codePoint)) { + // We need to discount non-letters since they may not be upper-case, but may + // still be part of a word (e.g. single quote or dash, as in "IT'S" or "FULL-TIME") + ++letterCount; + } } - // We know the first char is upper case. So we want to test if either everything - // else is lower case, or if everything else is upper case. If the string is - // exactly one char long, then we will arrive here with capsCount 1, and this is - // correct, too. + // We know the first char is upper case. So we want to test if either every letter other + // than the first is lower case, or if they are all upper case. If the string is exactly + // one char long, then we will arrive here with letterCount 1, and this is correct, too. if (1 == capsCount) return CAPITALIZE_FIRST; - return (len == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE); + return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE); } } |