am b75dee4b: Merge "Fix ArrayIndexOutOfBoundsException in WordComposer" into gingerbread

Merge commit 'b75dee4b00b31524ab73684a948b82b90bae7ba1' into gingerbread-plus-aosp

* commit 'b75dee4b00b31524ab73684a948b82b90bae7ba1':
  Fix ArrayIndexOutOfBoundsException in WordComposer
main
Tadashi G. Takaoka 2010-09-22 22:54:14 -07:00 committed by Android Git Automerger
commit 4fab9f2fee
1 changed files with 10 additions and 16 deletions

View File

@ -25,14 +25,14 @@ public class WordComposer {
/** /**
* The list of unicode values for each keystroke (including surrounding keys) * The list of unicode values for each keystroke (including surrounding keys)
*/ */
private ArrayList<int[]> mCodes; private final ArrayList<int[]> mCodes;
/** /**
* The word chosen from the candidate list, until it is committed. * The word chosen from the candidate list, until it is committed.
*/ */
private String mPreferredWord; private String mPreferredWord;
private StringBuilder mTypedWord; private final StringBuilder mTypedWord;
private int mCapsCount; private int mCapsCount;
@ -116,11 +116,14 @@ public class WordComposer {
* Delete the last keystroke as a result of hitting backspace. * Delete the last keystroke as a result of hitting backspace.
*/ */
public void deleteLast() { public void deleteLast() {
mCodes.remove(mCodes.size() - 1); final int codesSize = mCodes.size();
final int lastPos = mTypedWord.length() - 1; if (codesSize > 0) {
char last = mTypedWord.charAt(lastPos); mCodes.remove(codesSize - 1);
mTypedWord.deleteCharAt(lastPos); final int lastPos = mTypedWord.length() - 1;
if (Character.isUpperCase(last)) mCapsCount--; char last = mTypedWord.charAt(lastPos);
mTypedWord.deleteCharAt(lastPos);
if (Character.isUpperCase(last)) mCapsCount--;
}
} }
/** /**
@ -132,15 +135,6 @@ public class WordComposer {
if (wordSize == 0) { if (wordSize == 0) {
return null; return null;
} }
// StringBuffer sb = new StringBuffer(wordSize);
// for (int i = 0; i < wordSize; i++) {
// char c = (char) mCodes.get(i)[0];
// if (i == 0 && mIsCapitalized) {
// c = Character.toUpperCase(c);
// }
// sb.append(c);
// }
// return sb;
return mTypedWord; return mTypedWord;
} }