Fix string iterations in a couple places.
Seems I didn't get how to iterate on a String correctly >.> Talk about a big bug. Anyway, I think it's working now. Bug: 5955228 Change-Id: I988c900cf2a16c44b9505cfd4f77c7cda7e592f0main
parent
fbd83a8712
commit
9242a2bcf8
|
@ -75,7 +75,8 @@ class BinaryDictionaryGetter {
|
|||
// This assumes '%' is fully available as a non-separator, normal
|
||||
// character in a file name. This is probably true for all file systems.
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < name.length(); ++i) {
|
||||
final int nameLength = name.length();
|
||||
for (int i = 0; i < nameLength; i = name.offsetByCodePoints(i, 1)) {
|
||||
final int codePoint = name.codePointAt(i);
|
||||
if (isFileNameCharacter(codePoint)) {
|
||||
sb.appendCodePoint(codePoint);
|
||||
|
@ -92,7 +93,8 @@ class BinaryDictionaryGetter {
|
|||
*/
|
||||
private static String getWordListIdFromFileName(final String fname) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < fname.length(); ++i) {
|
||||
final int fnameLength = fname.length();
|
||||
for (int i = 0; i < fnameLength; i = fname.offsetByCodePoints(i, 1)) {
|
||||
final int codePoint = fname.codePointAt(i);
|
||||
if ('%' != codePoint) {
|
||||
sb.appendCodePoint(codePoint);
|
||||
|
|
|
@ -93,7 +93,8 @@ public class SettingsValues {
|
|||
mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols);
|
||||
mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols);
|
||||
if (LatinImeLogger.sDBG) {
|
||||
for (int i = 0; i < mMagicSpaceStrippers.length(); ++i) {
|
||||
final int length = mMagicSpaceStrippers.length();
|
||||
for (int i = 0; i < length; i = mMagicSpaceStrippers.offsetByCodePoints(i, 1)) {
|
||||
if (isMagicSpaceSwapper(mMagicSpaceStrippers.codePointAt(i))) {
|
||||
throw new RuntimeException("Char code " + mMagicSpaceStrippers.codePointAt(i)
|
||||
+ " is both a magic space swapper and stripper.");
|
||||
|
@ -234,10 +235,12 @@ public class SettingsValues {
|
|||
}
|
||||
|
||||
public boolean isMagicSpaceStripper(int code) {
|
||||
// TODO: this does not work if the code does not fit in a char
|
||||
return mMagicSpaceStrippers.contains(String.valueOf((char)code));
|
||||
}
|
||||
|
||||
public boolean isMagicSpaceSwapper(int code) {
|
||||
// TODO: this does not work if the code does not fit in a char
|
||||
return mMagicSpaceSwappers.contains(String.valueOf((char)code));
|
||||
}
|
||||
|
||||
|
|
|
@ -221,7 +221,8 @@ public class WordComposer {
|
|||
if (mTrailingSingleQuotesCount > 0) {
|
||||
--mTrailingSingleQuotesCount;
|
||||
} else {
|
||||
for (int i = mTypedWord.length() - 1; i >= 0; --i) {
|
||||
for (int i = mTypedWord.offsetByCodePoints(mTypedWord.length(), -1);
|
||||
i >= 0; i = mTypedWord.offsetByCodePoints(i, -1)) {
|
||||
if (Keyboard.CODE_SINGLE_QUOTE != mTypedWord.codePointAt(i)) break;
|
||||
++mTrailingSingleQuotesCount;
|
||||
}
|
||||
|
|
|
@ -431,9 +431,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
|||
// If the first char is not uppercase, then the word is either all lower case,
|
||||
// and in either case we return CAPITALIZE_NONE.
|
||||
if (!Character.isUpperCase(text.codePointAt(0))) return CAPITALIZE_NONE;
|
||||
final int len = text.codePointCount(0, text.length());
|
||||
final int len = text.length();
|
||||
int capsCount = 1;
|
||||
for (int i = 1; i < len; ++i) {
|
||||
for (int i = 1; i < len; i = text.offsetByCodePoints(i, 1)) {
|
||||
if (1 != capsCount && i != capsCount) break;
|
||||
if (Character.isUpperCase(text.codePointAt(i))) ++capsCount;
|
||||
}
|
||||
|
@ -522,13 +522,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
|||
// Filter contents
|
||||
final int length = text.length();
|
||||
int letterCount = 0;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
for (int i = 0; i < length; i = text.offsetByCodePoints(i, 1)) {
|
||||
final int codePoint = text.codePointAt(i);
|
||||
// Any word containing a '@' is probably an e-mail address
|
||||
// Any word containing a '/' is probably either an ad-hoc combination of two
|
||||
// words or a URI - in either case we don't want to spell check that
|
||||
if ('@' == codePoint
|
||||
|| '/' == codePoint) return true;
|
||||
if ('@' == codePoint || '/' == codePoint) return true;
|
||||
if (isLetterCheckableByLanguage(codePoint, script)) ++letterCount;
|
||||
}
|
||||
// Guestimate heuristic: perform spell checking if at least 3/4 of the characters
|
||||
|
@ -570,7 +569,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
|||
suggestionsLimit);
|
||||
final WordComposer composer = new WordComposer();
|
||||
final int length = text.length();
|
||||
for (int i = 0; i < length; ++i) {
|
||||
for (int i = 0; i < length; i = text.offsetByCodePoints(i, 1)) {
|
||||
final int character = text.codePointAt(i);
|
||||
final int proximityIndex =
|
||||
SpellCheckerProximityInfo.getIndexOfCodeForScript(character, mScript);
|
||||
|
|
|
@ -133,7 +133,7 @@ public class InputLogicTests extends ServiceTestCase<LatinIME> {
|
|||
}
|
||||
|
||||
private void type(final String stringToType) {
|
||||
for (int i = 0; i < stringToType.length(); ++i) {
|
||||
for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) {
|
||||
type(stringToType.codePointAt(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ public class FusionDictionary implements Iterable<Word> {
|
|||
static private int[] getCodePoints(String word) {
|
||||
final int wordLength = word.length();
|
||||
int[] array = new int[word.codePointCount(0, wordLength)];
|
||||
for (int i = 0; i < wordLength; ++i) {
|
||||
for (int i = 0; i < wordLength; i = word.offsetByCodePoints(i, 1)) {
|
||||
array[i] = word.codePointAt(i);
|
||||
}
|
||||
return array;
|
||||
|
|
Loading…
Reference in New Issue