aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/utils/UIHelper.java
diff options
context:
space:
mode:
authorM. Dietrich <mdt@emdete.de>2014-09-03 16:10:50 +0200
committerM. Dietrich <mdt@emdete.de>2014-09-03 16:10:50 +0200
commit584984807e3f9e05c7f556d1181a3301db6a8b60 (patch)
treeb4a5127ec6a81a96f5847b70022383024a14ad66 /src/eu/siacs/conversations/utils/UIHelper.java
parentcb3ba4045e78320d7c670edbd7bc320ebe38e301 (diff)
make pattern static
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/utils/UIHelper.java36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java
index 072fe715..1c1bb893 100644
--- a/src/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/eu/siacs/conversations/utils/UIHelper.java
@@ -546,28 +546,32 @@ public class UIHelper {
}
}
- private static final Pattern armorRegex(String regex) { return Pattern.compile("(^|\\s+)" + regex + "(\\s+|$)"); }
-
- private static final String armorReplacement(String replacement) { return "$1" + replacement + "$2"; }
+ private static final Pattern armorRegex(String regex) {
+ return Pattern.compile("(^|\\s+)" + regex + "(\\s+|$)"); }
+
+ private static final String armorReplacement(String replacement) {
+ return "$1" + replacement + "$2"; }
+
+ private static final Object[][] patterns = new Object[][]{
+ {armorRegex(":-?\\)"), armorReplacement("😃"), },
+ {armorRegex(";-?\\)"), armorReplacement("😉"), },
+ {armorRegex(":-?D"), armorReplacement("😀"), },
+ {armorRegex(":-?[Ppb]"), armorReplacement("😋"), },
+ {armorRegex("8-?\\)"), armorReplacement("😎"), },
+ {armorRegex(":-?\\|"), armorReplacement("😐"), },
+ {armorRegex(":-?[/\\\\]"), armorReplacement("😕"), },
+ {armorRegex(":-?\\*"), armorReplacement("😗"), },
+ {armorRegex(":-?[0Oo]"), armorReplacement("😮"), },
+ {armorRegex(":-?\\("), armorReplacement("😞"), },
+ {armorRegex("\\^\\^"), armorReplacement("😁"), },
+ };
public static String transformAsciiEmoticons(String body) {
if (body != null) {
// see https://developer.android.com/reference/java/util/regex/Pattern.html
// see http://userguide.icu-project.org/strings/regexp
// see https://de.wikipedia.org/wiki/Unicodeblock_Smileys
- for (Object[] r: new Object[][]{
- {armorRegex(":-?\\)"), armorReplacement("😃"), },
- {armorRegex(";-?\\)"), armorReplacement("😉"), },
- {armorRegex(":-?D"), armorReplacement("😀"), },
- {armorRegex(":-?[Ppb]"), armorReplacement("😋"), },
- {armorRegex("8-?\\)"), armorReplacement("😎"), },
- {armorRegex(":-?\\|"), armorReplacement("😐"), },
- {armorRegex(":-?[/\\\\]"), armorReplacement("😕"), },
- {armorRegex(":-?\\*"), armorReplacement("😗"), },
- {armorRegex(":-?[0Oo]"), armorReplacement("😮"), },
- {armorRegex(":-?\\("), armorReplacement("😞"), },
- {armorRegex("\\^\\^"), armorReplacement("😁"), },
- }) {
+ for (Object[] r: patterns) {
Pattern pattern = (Pattern)r[0];
String replacement = (String)r[1];
body = pattern.matcher(body).replaceAll(replacement);