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