use class, use codepoint
This commit is contained in:
parent
584984807e
commit
0a686bc71c
|
@ -546,35 +546,36 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern armorRegex(String regex) {
|
private final static class EmoticonPattern {
|
||||||
return Pattern.compile("(^|\\s+)" + regex + "(\\s+|$)"); }
|
Pattern pattern;
|
||||||
|
String replacement;
|
||||||
|
EmoticonPattern(String ascii, int unicode) {
|
||||||
|
this.pattern = Pattern.compile("(?<=(^|\\s))" + ascii + "(?=(\\s|$))");
|
||||||
|
this.replacement = new String(new int[]{unicode, }, 0, 1);
|
||||||
|
}
|
||||||
|
String replaceAll(String body) {
|
||||||
|
return pattern.matcher(body).replaceAll(replacement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String armorReplacement(String replacement) {
|
private static final EmoticonPattern[] patterns = new EmoticonPattern[] {
|
||||||
return "$1" + replacement + "$2"; }
|
new EmoticonPattern(":-?\\)", 0x1f603),
|
||||||
|
new EmoticonPattern(";-?\\)", 0x1f609),
|
||||||
private static final Object[][] patterns = new Object[][]{
|
new EmoticonPattern(":-?D", 0x1f600),
|
||||||
{armorRegex(":-?\\)"), armorReplacement("😃"), },
|
new EmoticonPattern(":-?[Ppb]", 0x1f60b),
|
||||||
{armorRegex(";-?\\)"), armorReplacement("😉"), },
|
new EmoticonPattern("8-?\\)", 0x1f60e),
|
||||||
{armorRegex(":-?D"), armorReplacement("😀"), },
|
new EmoticonPattern(":-?\\|", 0x1f610),
|
||||||
{armorRegex(":-?[Ppb]"), armorReplacement("😋"), },
|
new EmoticonPattern(":-?[/\\\\]", 0x1f615),
|
||||||
{armorRegex("8-?\\)"), armorReplacement("😎"), },
|
new EmoticonPattern(":-?\\*", 0x1f617),
|
||||||
{armorRegex(":-?\\|"), armorReplacement("😐"), },
|
new EmoticonPattern(":-?[0Oo]", 0x1f62e),
|
||||||
{armorRegex(":-?[/\\\\]"), armorReplacement("😕"), },
|
new EmoticonPattern(":-?\\(", 0x1f61e),
|
||||||
{armorRegex(":-?\\*"), armorReplacement("😗"), },
|
new EmoticonPattern("\\^\\^", 0x1f601),
|
||||||
{armorRegex(":-?[0Oo]"), armorReplacement("😮"), },
|
|
||||||
{armorRegex(":-?\\("), armorReplacement("😞"), },
|
|
||||||
{armorRegex("\\^\\^"), armorReplacement("😁"), },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static String transformAsciiEmoticons(String body) {
|
public static String transformAsciiEmoticons(String body) {
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
// see https://developer.android.com/reference/java/util/regex/Pattern.html
|
for (EmoticonPattern p: patterns) {
|
||||||
// see http://userguide.icu-project.org/strings/regexp
|
body = p.replaceAll(body);
|
||||||
// see https://de.wikipedia.org/wiki/Unicodeblock_Smileys
|
|
||||||
for (Object[] r: patterns) {
|
|
||||||
Pattern pattern = (Pattern)r[0];
|
|
||||||
String replacement = (String)r[1];
|
|
||||||
body = pattern.matcher(body).replaceAll(replacement);
|
|
||||||
}
|
}
|
||||||
body = body.trim();
|
body = body.trim();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue