Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71915a37 authored by Jean Chalard's avatar Jean Chalard Committed by Android (Google) Code Review
Browse files

Merge "Fix string iterations in a couple places."

parents ebfae7f5 9242a2bc
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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);
+4 −1
Original line number Diff line number Diff line
@@ -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));
    }

+2 −1
Original line number Diff line number Diff line
@@ -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;
            }
+5 −6
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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));
        }
    }
Loading