diff options
author | 2014-04-19 01:03:17 +0000 | |
---|---|---|
committer | 2014-04-19 01:03:17 +0000 | |
commit | 8e95b2f5a7ecedc2f1ee7ba71ed10f3df17e2ece (patch) | |
tree | 54cfe6620fbb2ad1b61fdc84452f43ded8a15a91 /java/src/com/android/inputmethod/latin/WordComposer.java | |
parent | eb17716b8a310f265f5c0e41a8264013a5dd1b6e (diff) | |
parent | 11b707616800e08891f6b610be90033acda8ffd0 (diff) | |
download | latinime-8e95b2f5a7ecedc2f1ee7ba71ed10f3df17e2ece.tar.gz latinime-8e95b2f5a7ecedc2f1ee7ba71ed10f3df17e2ece.tar.xz latinime-8e95b2f5a7ecedc2f1ee7ba71ed10f3df17e2ece.zip |
Merge "Fix a bug for counting code points in WordComposer.java"
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/WordComposer.java | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 1268e5aac..d755195f2 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -129,22 +129,25 @@ public final class WordComposer { * -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) { - final int i = mTypedWordCache.length() - 1 - trailingSingleQuotesCount(); - if (i < 0) { + final int[] destination) { + // lastIndex is exclusive + final int lastIndex = mTypedWordCache.length() - trailingSingleQuotesCount(); + if (lastIndex <= 0) { // The string is empty or contains only single quotes. return 0; } - final int codePointSize = Character.codePointCount(mTypedWordCache, 0, i); - if (codePointSize > maxSize) { + + // The following function counts the number of code points in the text range which begins + // at index 0 and extends to the character at lastIndex. + final int codePointSize = Character.codePointCount(mTypedWordCache, 0, lastIndex); + if (codePointSize > destination.length) { return -1; } return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0, - i + 1, true /* downCase */); + lastIndex, true /* downCase */); } public boolean isSingleLetter() { |