Merge "Refactor and squash long-standing bugs (A2)"

main
Jean Chalard 2012-06-26 03:19:20 -07:00 committed by Android (Google) Code Review
commit 61c1002b6b
1 changed files with 9 additions and 13 deletions

View File

@ -252,7 +252,7 @@ public class Suggest {
} }
for (final SuggestedWordInfo suggestion : localSuggestions) { for (final SuggestedWordInfo suggestion : localSuggestions) {
final String suggestionStr = suggestion.mWord.toString(); final String suggestionStr = suggestion.mWord.toString();
addWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(), addWord(suggestionStr, null,
suggestion.mScore, dicTypeId, Dictionary.BIGRAM, suggestion.mScore, dicTypeId, Dictionary.BIGRAM,
suggestions, consideredWord); suggestions, consideredWord);
} }
@ -279,7 +279,7 @@ public class Suggest {
wordComposerForLookup, prevWordForBigram, proximityInfo); wordComposerForLookup, prevWordForBigram, proximityInfo);
for (final SuggestedWordInfo suggestion : localSuggestions) { for (final SuggestedWordInfo suggestion : localSuggestions) {
final String suggestionStr = suggestion.mWord.toString(); final String suggestionStr = suggestion.mWord.toString();
addWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(), addWord(suggestionStr, null,
suggestion.mScore, dicTypeId, Dictionary.UNIGRAM, suggestion.mScore, dicTypeId, Dictionary.UNIGRAM,
suggestions, consideredWord); suggestions, consideredWord);
} }
@ -388,17 +388,17 @@ public class Suggest {
return suggestionsList; return suggestionsList;
} }
// TODO: Use codepoint instead of char public boolean addWord(final String word, int[] indices,
public boolean addWord(final char[] word, int[] indices, final int offset, final int length,
int score, final int dicTypeId, final int dataType, int score, final int dicTypeId, final int dataType,
final ArrayList<SuggestedWordInfo> suggestions, final String consideredWord) { final ArrayList<SuggestedWordInfo> suggestions, final String consideredWord) {
int dataTypeForLog = dataType; int dataTypeForLog = dataType;
final int prefMaxSuggestions = MAX_SUGGESTIONS; final int prefMaxSuggestions = MAX_SUGGESTIONS;
final int length = word.codePointCount(0, word.length());
int pos = 0; int pos = 0;
// Check if it's the same word, only caps are different // Check if it's the same word, only caps are different
if (StringUtils.equalsIgnoreCase(consideredWord, word, offset, length)) { if (StringUtils.equalsIgnoreCase(consideredWord, word)) {
// TODO: remove this surrounding if clause and move this logic to // TODO: remove this surrounding if clause and move this logic to
// getSuggestedWordBuilder. // getSuggestedWordBuilder.
if (suggestions.size() > 0) { if (suggestions.size() > 0) {
@ -407,7 +407,7 @@ public class Suggest {
// frequency to determine the insertion position. This does not ensure strictly // frequency to determine the insertion position. This does not ensure strictly
// correct ordering, but ensures the top score is on top which is enough for // correct ordering, but ensures the top score is on top which is enough for
// removing duplicates correctly. // removing duplicates correctly.
if (StringUtils.equalsIgnoreCase(currentHighestWord.mWord, word, offset, length) if (StringUtils.equalsIgnoreCase(currentHighestWord.mWord, word)
&& score <= currentHighestWord.mScore) { && score <= currentHighestWord.mScore) {
pos = 1; pos = 1;
} }
@ -430,16 +430,12 @@ public class Suggest {
} }
final StringBuilder sb = new StringBuilder(getApproxMaxWordLength()); final StringBuilder sb = new StringBuilder(getApproxMaxWordLength());
// TODO: Must pay attention to locale when changing case.
if (mIsAllUpperCase) { if (mIsAllUpperCase) {
sb.append(new String(word, offset, length).toUpperCase()); sb.append(word.toUpperCase(mLocale));
} else if (mIsFirstCharCapitalized) { } else if (mIsFirstCharCapitalized) {
sb.append(Character.toUpperCase(word[offset])); sb.append(StringUtils.toTitleCase(word, mLocale));
if (length > 1) {
sb.append(word, offset + 1, length - 1);
}
} else { } else {
sb.append(word, offset, length); sb.append(word);
} }
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);