Skip to content

Commit

Permalink
Fix start index correct handling when computing length
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <daniele.athome@gmail.com>
  • Loading branch information
daniele-athome committed Aug 18, 2014
1 parent 85e1f74 commit 5d5d0b5
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1393,18 +1393,17 @@ public static void addEmojis(Context context, Spannable text, int emojiSize) {
*/
public static void addEmojis(Context context, Spannable text, int emojiSize, int index, int length) {
int textLength = text.length();
if (length < 0)
length = textLength;
else if (length > textLength)
length = textLength;
int textLengthToProcessMax = textLength - index;
int textLengthToProcess = length < 0 || length >= textLengthToProcessMax ? textLength : (length+index);

// remove spans throughout all text
EmojiconSpan[] oldSpans = text.getSpans(0, textLength, EmojiconSpan.class);
for (int i = 0; i < oldSpans.length; i++) {
text.removeSpan(oldSpans[i]);
}

int skip;
for (int i = index; i < length; i += skip) {
for (int i = index; i < textLengthToProcess; i += skip) {
skip = 0;
int icon = 0;
char c = text.charAt(i);
Expand Down

0 comments on commit 5d5d0b5

Please sign in to comment.