diff options
author | 2014-04-09 09:57:00 +0000 | |
---|---|---|
committer | 2014-04-09 09:57:00 +0000 | |
commit | 77dd17ad36082bb7023c37976a44028bad7e62c5 (patch) | |
tree | 6dff8fc804fb84efa4800754148e34f62219937b /java/src/com/android/inputmethod/latin/WordComposer.java | |
parent | f9d8ba3ada1fbfdfe43b584e7cf280d151ad0c27 (diff) | |
parent | 5f430e0189f6c0a1a34edb0e00809bc53a525a7b (diff) | |
download | latinime-77dd17ad36082bb7023c37976a44028bad7e62c5.tar.gz latinime-77dd17ad36082bb7023c37976a44028bad7e62c5.tar.xz latinime-77dd17ad36082bb7023c37976a44028bad7e62c5.zip |
Merge "[CB25] Refactor some array copying"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 81d642ff2..02f18cdd3 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -131,29 +131,42 @@ public final class WordComposer { return mCodePointSize; } - public boolean isSingleLetter() { - return size() == 1; + /** + * Copy the code points in the typed word to a destination array of ints. + * + * If the array is too small to hold the code points in the typed word, nothing is copied and + * -1 is returned. + * + * @param destination the array of ints. + * @param maxSize the size of the array. + * @return the number of copied code points. + */ + public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount( + final int[] destination, final int maxSize) { + int i = mTypedWordCache.length() - 1; + while (i >= 0 && mTypedWordCache.charAt(i) == Constants.CODE_SINGLE_QUOTE) { + --i; + } + if (i < 0) { + // The string is empty or contains only single quotes. + return 0; + } + final int codePointSize = Character.codePointCount(mTypedWordCache, 0, i); + if (codePointSize > maxSize) { + return -1; + } + return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0, + i + 1, true /* downCase */); } - // When the composition contains trailing quotes, we don't pass them to the suggestion engine. - // This is because "'tgis'" should be corrected to "'this'", but we can't afford to consider - // single quotes as separators because of their very common use as apostrophes. - public int sizeWithoutTrailingSingleQuotes() { - return size() - mTrailingSingleQuotesCount; + public boolean isSingleLetter() { + return size() == 1; } public final boolean isComposingWord() { return size() > 0; } - // TODO: make sure that the index should not exceed MAX_WORD_LENGTH - public int getCodeAt(int index) { - if (index >= MAX_WORD_LENGTH) { - return -1; - } - return mPrimaryKeyCodes[index]; - } - public InputPointers getInputPointers() { return mInputPointers; } |