|
@@ -56,6 +56,8 @@ public final class Styliser {
|
56
|
56
|
public static final char CODE_HYPERLINK = 5;
|
57
|
57
|
/** Character used to indicate channel links. */
|
58
|
58
|
public static final char CODE_CHANNEL = 6;
|
|
59
|
+ /** Character used to indicate smilies. */
|
|
60
|
+ public static final char CODE_SMILIE = 7;
|
59
|
61
|
/** The character used for stopping all formatting. */
|
60
|
62
|
public static final char CODE_STOP = 15;
|
61
|
63
|
/** Character used to indicate nickname links. */
|
|
@@ -70,7 +72,8 @@ public final class Styliser {
|
70
|
72
|
public static final char CODE_UNDERLINE = 31;
|
71
|
73
|
|
72
|
74
|
/** Internal chars. */
|
73
|
|
- private static final String INTERNAL_CHARS = String.valueOf(CODE_HYPERLINK) + CODE_CHANNEL;
|
|
75
|
+ private static final String INTERNAL_CHARS = String.valueOf(CODE_HYPERLINK)
|
|
76
|
+ + CODE_NICKNAME + CODE_CHANNEL + CODE_SMILIE;
|
74
|
77
|
|
75
|
78
|
/** Regexp to match characters which shouldn't be used in channel links. */
|
76
|
79
|
private static final String RESERVED_CHARS = "[^\\s" + CODE_BOLD + CODE_COLOUR
|
|
@@ -160,7 +163,7 @@ public final class Styliser {
|
160
|
163
|
int offset = ooffset;
|
161
|
164
|
int position = 0;
|
162
|
165
|
|
163
|
|
- String target = doLinks(new String(chars).replaceAll(INTERNAL_CHARS, ""));
|
|
166
|
+ String target = doSmilies(doLinks(new String(chars).replaceAll(INTERNAL_CHARS, "")));
|
164
|
167
|
|
165
|
168
|
target = target.replaceAll(URL_CHANNEL, CODE_CHANNEL + "$0" + CODE_CHANNEL);
|
166
|
169
|
|
|
@@ -232,6 +235,20 @@ public final class Styliser {
|
232
|
235
|
|
233
|
236
|
return target;
|
234
|
237
|
}
|
|
238
|
+
|
|
239
|
+ /**
|
|
240
|
+ * Applies the smilie styles to the target.
|
|
241
|
+ *
|
|
242
|
+ * @param string The string to be smilified
|
|
243
|
+ * @return A copy of the string with smilies marked up
|
|
244
|
+ * @since 0.6.3
|
|
245
|
+ */
|
|
246
|
+ public static String doSmilies(final String string) {
|
|
247
|
+ // TODO: read types from config. Check if they're enabled.
|
|
248
|
+
|
|
249
|
+ return string.replaceAll("(\\s|^):[\\\\/](\\s|$)", "\\1" + CODE_SMILIE + ":/"
|
|
250
|
+ + CODE_SMILIE + "\\2");
|
|
251
|
+ }
|
235
|
252
|
|
236
|
253
|
/**
|
237
|
254
|
* Strips all recognised control codes from the input string.
|
|
@@ -278,6 +295,7 @@ public final class Styliser {
|
278
|
295
|
pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
|
279
|
296
|
pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
|
280
|
297
|
pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
|
|
298
|
+ pos = checkChar(pos, input.indexOf(CODE_SMILIE));
|
281
|
299
|
pos = checkChar(pos, input.indexOf(CODE_NEGATE));
|
282
|
300
|
|
283
|
301
|
return input.substring(0, pos);
|
|
@@ -479,6 +497,19 @@ public final class Styliser {
|
479
|
497
|
toggleAttribute(attribs, "NegateControl");
|
480
|
498
|
return 1;
|
481
|
499
|
}
|
|
500
|
+
|
|
501
|
+ // Smilies!!
|
|
502
|
+ if (string.charAt(0) == CODE_SMILIE) {
|
|
503
|
+ if (attribs.getAttribute(IRCTextAttribute.SMILEY) == null) {
|
|
504
|
+ final String smilie = readUntilControl(string.substring(1));
|
|
505
|
+
|
|
506
|
+ attribs.addAttribute(IRCTextAttribute.SMILEY, "smilie-" + smilie);
|
|
507
|
+ } else {
|
|
508
|
+ attribs.removeAttribute(IRCTextAttribute.SMILEY);
|
|
509
|
+ }
|
|
510
|
+
|
|
511
|
+ return 1;
|
|
512
|
+ }
|
482
|
513
|
|
483
|
514
|
return 0;
|
484
|
515
|
}
|