From f53e44a2910725fb0604b8255343042a7417efe0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 29 Sep 2017 23:27:08 +0200 Subject: [PATCH] refactor emoji detector and fix fitzpatrick followed by zwj --- .../siacs/conversations/utils/Emoticons.java | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/Emoticons.java b/src/main/java/eu/siacs/conversations/utils/Emoticons.java index 84760fe66..7435f9f84 100644 --- a/src/main/java/eu/siacs/conversations/utils/Emoticons.java +++ b/src/main/java/eu/siacs/conversations/utils/Emoticons.java @@ -1,12 +1,8 @@ package eu.siacs.conversations.utils; -import android.util.Log; - import java.util.ArrayList; import java.util.List; -import eu.siacs.conversations.Config; - public class Emoticons { private static final UnicodeRange MISC_SYMBOLS_AND_PICTOGRAPHS = new UnicodeRange(0x1F300,0x1F5FF); @@ -68,45 +64,46 @@ public class Emoticons { public boolean offer(int codepoint) { + boolean add = false; if (this.codepoints.size() == 0) { if (REGIONAL_INDICATORS.contains(codepoint)) { - codepoints.add(codepoint); - return true; + add = true; } else if (EMOJIS.contains(codepoint) && !FITZPATRICK.contains(codepoint) && codepoint != ZWJ) { - codepoints.add(codepoint); - return true; + add = true; } } else { int previous = codepoints.get(codepoints.size() -1); if (REGIONAL_INDICATORS.contains(previous) && REGIONAL_INDICATORS.contains(codepoint)) { if (codepoints.size() == 1) { - codepoints.add(codepoint); - return true; + add = true; } } else if (previous == VARIATION_16) { if (isMerger(codepoint)) { - codepoints.add(codepoint); - return true; + add = true; } - } else if (isMerger(previous)) { - if (EMOJIS.contains(codepoint)) { - codepoints.add(codepoint); - return true; + } else if (FITZPATRICK.contains(previous)) { + if (codepoint == ZWJ || EMOJIS.contains(codepoint)) { + add = true; } - } else { - if (isMerger(codepoint)) { - codepoints.add(codepoint); - return true; - } else if (codepoint == VARIATION_16 && EMOJIS.contains(previous)) { - codepoints.add(codepoint); - return true; + } else if (ZWJ == previous) { + if (EMOJIS.contains(codepoint) || FITZPATRICK.contains(codepoint)) { + add = true; } + } else if (isMerger(codepoint)) { + add = true; + } else if (codepoint == VARIATION_16 && EMOJIS.contains(previous)) { + add = true; } } - return false; + if (add) { + codepoints.add(codepoint); + return true; + } else { + return false; + } } - public static boolean isMerger(int codepoint) { + private static boolean isMerger(int codepoint) { return codepoint == ZWJ || FITZPATRICK.contains(codepoint); }