am 85170a9c: Merge "Be stricter for ruling characters out of spell checking"

* commit '85170a9c17e7fbefb3d9a6dba0e211b72899aeae':
  Be stricter for ruling characters out of spell checking
main
Jean Chalard 2011-11-11 15:58:56 -08:00 committed by Android Git Automerger
commit 99a114e529
1 changed files with 25 additions and 4 deletions

View File

@ -361,6 +361,27 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
mLocale = LocaleUtils.constructLocaleFromString(localeString); mLocale = LocaleUtils.constructLocaleFromString(localeString);
} }
/*
* Returns whether the code point is a letter that makes sense for the specified
* locale for this spell checker.
* The dictionaries supported by Latin IME are described in res/xml/spellchecker.xml
* and is limited to EFIGS language.
* Hence at the moment this explicitly excludes non-Latin scripts, including CJK
* characters, but also Cyrillic, Arabic or Hebrew characters.
* The locale should be used to rule out inappropriate characters when we support
* spellchecking other languages like Russian.
*/
private static boolean isLetterCheckableByLanguage(final int codePoint,
final Locale locale) {
// Our supported dictionaries (EFIGS) at the moment only includes characters
// in the C0, C1, Latin Extended A and B, IPA extensions unicode blocks.
// As it happens, those are back-to-back in the code range 0x40 to 0x2AF, so
// the below is a very efficient way to test for it. As for the 0-0x3F, it's
// excluded from isLetter anyway.
// TODO: change this to use locale when we support other scripts
return codePoint <= 0x2AF && Character.isLetter(codePoint);
}
/** /**
* Finds out whether a particular string should be filtered out of spell checking. * Finds out whether a particular string should be filtered out of spell checking.
* *
@ -369,7 +390,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
* @param text the string to evaluate. * @param text the string to evaluate.
* @return true if we should filter this text out, false otherwise * @return true if we should filter this text out, false otherwise
*/ */
private static boolean shouldFilterOut(final String text) { private static boolean shouldFilterOut(final String text, final Locale locale) {
if (TextUtils.isEmpty(text) || text.length() <= 1) return true; if (TextUtils.isEmpty(text) || text.length() <= 1) return true;
// TODO: check if an equivalent processing can't be done more quickly with a // TODO: check if an equivalent processing can't be done more quickly with a
@ -377,7 +398,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// Filter by first letter // Filter by first letter
final int firstCodePoint = text.codePointAt(0); final int firstCodePoint = text.codePointAt(0);
// Filter out words that don't start with a letter or an apostrophe // Filter out words that don't start with a letter or an apostrophe
if (!Character.isLetter(firstCodePoint) if (!isLetterCheckableByLanguage(firstCodePoint, locale)
&& '\'' != firstCodePoint) return true; && '\'' != firstCodePoint) return true;
// Filter contents // Filter contents
@ -390,7 +411,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// words or a URI - in either case we don't want to spell check that // words or a URI - in either case we don't want to spell check that
if ('@' == codePoint if ('@' == codePoint
|| '/' == codePoint) return true; || '/' == codePoint) return true;
if (Character.isLetter(codePoint)) ++letterCount; if (isLetterCheckableByLanguage(codePoint, locale)) ++letterCount;
} }
// Guestimate heuristic: perform spell checking if at least 3/4 of the characters // Guestimate heuristic: perform spell checking if at least 3/4 of the characters
// in this word are letters // in this word are letters
@ -409,7 +430,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
try { try {
final String text = textInfo.getText(); final String text = textInfo.getText();
if (shouldFilterOut(text)) { if (shouldFilterOut(text, mLocale)) {
DictAndProximity dictInfo = null; DictAndProximity dictInfo = null;
try { try {
dictInfo = mDictionaryPool.takeOrGetNull(); dictInfo = mDictionaryPool.takeOrGetNull();