fix emojis not rendering correctly with trailing variant selector. fixes #3819

This commit is contained in:
Daniel Gultsch 2020-07-09 17:43:30 +02:00
parent 14bb8b0cf1
commit 71a56002fe
1 changed files with 228 additions and 227 deletions

View File

@ -29,11 +29,11 @@
package eu.siacs.conversations.utils;
import android.support.annotation.NonNull;
import android.util.LruCache;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;
@ -107,7 +107,7 @@ public class Emoticons {
return symbols;
}
public static Pattern getEmojiPattern(CharSequence input) {
public static Pattern getEmojiPattern(final CharSequence input) {
Pattern pattern = CACHE.get(input);
if (pattern == null) {
pattern = generatePattern(input);
@ -119,7 +119,7 @@ public class Emoticons {
private static Pattern generatePattern(CharSequence input) {
final HashSet<String> emojis = new HashSet<>();
int i = 0;
for(Symbol symbol : parse(input.toString())) {
for (final Symbol symbol : parse(input.toString())) {
if (symbol instanceof Emoji) {
emojis.add(symbol.toString());
if (++i >= MAX_EMOIJS) {
@ -156,9 +156,9 @@ public class Emoticons {
private final String value;
public Symbol(List<Integer> codepoints) {
StringBuilder builder = new StringBuilder();
for(Integer codepoint : codepoints) {
Symbol(List<Integer> codepoints) {
final StringBuilder builder = new StringBuilder();
for (final Integer codepoint : codepoints) {
builder.appendCodePoint(codepoint);
}
this.value = builder.toString();
@ -166,6 +166,7 @@ public class Emoticons {
abstract boolean isEmoji();
@NonNull
@Override
public String toString() {
return value;
@ -174,7 +175,7 @@ public class Emoticons {
public static class Emoji extends Symbol {
public Emoji(List<Integer> codepoints) {
Emoji(List<Integer> codepoints) {
super(codepoints);
}
@ -221,7 +222,7 @@ public class Emoticons {
} else if (REGIONAL_INDICATORS.contains(previous) && REGIONAL_INDICATORS.contains(codepoint)) {
add = codepoints.size() == 1;
} else if (previous == VARIATION_16) {
add = isMerger(codepoint);
add = isMerger(codepoint) || codepoint == VARIATION_16;
} else if (FITZPATRICK.contains(previous)) {
add = codepoint == ZWJ;
} else if (ZWJ == previous) {
@ -257,7 +258,7 @@ public class Emoticons {
public static class UnicodeBlocks implements UnicodeSet {
final UnicodeSet[] unicodeSets;
public UnicodeBlocks(UnicodeSet... sets) {
UnicodeBlocks(final UnicodeSet... sets) {
this.unicodeSets = sets;
}
@ -280,7 +281,7 @@ public class Emoticons {
private final List<Integer> list;
public UnicodeList(Integer... codes) {
UnicodeList(final Integer... codes) {
this.list = Arrays.asList(codes);
}