refactor emoji detector and fix fitzpatrick followed by zwj

This commit is contained in:
Daniel Gultsch 2017-09-29 23:27:08 +02:00
parent f0e48c8af5
commit f53e44a291
1 changed files with 22 additions and 25 deletions

View File

@ -1,12 +1,8 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
public class Emoticons { public class Emoticons {
private static final UnicodeRange MISC_SYMBOLS_AND_PICTOGRAPHS = new UnicodeRange(0x1F300,0x1F5FF); private static final UnicodeRange MISC_SYMBOLS_AND_PICTOGRAPHS = new UnicodeRange(0x1F300,0x1F5FF);
@ -68,45 +64,46 @@ public class Emoticons {
public boolean offer(int codepoint) { public boolean offer(int codepoint) {
boolean add = false;
if (this.codepoints.size() == 0) { if (this.codepoints.size() == 0) {
if (REGIONAL_INDICATORS.contains(codepoint)) { if (REGIONAL_INDICATORS.contains(codepoint)) {
codepoints.add(codepoint); add = true;
return true;
} else if (EMOJIS.contains(codepoint) && !FITZPATRICK.contains(codepoint) && codepoint != ZWJ) { } else if (EMOJIS.contains(codepoint) && !FITZPATRICK.contains(codepoint) && codepoint != ZWJ) {
codepoints.add(codepoint); add = true;
return true;
} }
} else { } else {
int previous = codepoints.get(codepoints.size() -1); int previous = codepoints.get(codepoints.size() -1);
if (REGIONAL_INDICATORS.contains(previous) && REGIONAL_INDICATORS.contains(codepoint)) { if (REGIONAL_INDICATORS.contains(previous) && REGIONAL_INDICATORS.contains(codepoint)) {
if (codepoints.size() == 1) { if (codepoints.size() == 1) {
codepoints.add(codepoint); add = true;
return true;
} }
} else if (previous == VARIATION_16) { } else if (previous == VARIATION_16) {
if (isMerger(codepoint)) { if (isMerger(codepoint)) {
codepoints.add(codepoint); add = true;
return true;
} }
} else if (isMerger(previous)) { } else if (FITZPATRICK.contains(previous)) {
if (EMOJIS.contains(codepoint)) { if (codepoint == ZWJ || EMOJIS.contains(codepoint)) {
codepoints.add(codepoint); add = true;
return true;
} }
} else { } else if (ZWJ == previous) {
if (isMerger(codepoint)) { if (EMOJIS.contains(codepoint) || FITZPATRICK.contains(codepoint)) {
codepoints.add(codepoint); add = true;
return true; }
} else if (isMerger(codepoint)) {
add = true;
} else if (codepoint == VARIATION_16 && EMOJIS.contains(previous)) { } else if (codepoint == VARIATION_16 && EMOJIS.contains(previous)) {
add = true;
}
}
if (add) {
codepoints.add(codepoint); codepoints.add(codepoint);
return true; return true;
} } else {
}
}
return false; return false;
} }
}
public static boolean isMerger(int codepoint) { private static boolean isMerger(int codepoint) {
return codepoint == ZWJ || FITZPATRICK.contains(codepoint); return codepoint == ZWJ || FITZPATRICK.contains(codepoint);
} }