From 95bfb8ac474d242f7abe83709df5c853a6d08619 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 4 Dec 2012 16:11:18 +0900 Subject: 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 --- .../spellcheck/AndroidSpellCheckerService.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java') 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); } } -- cgit v1.2.3-83-g751a