瀏覽代碼

Issue 1576

git-svn-id: http://svn.dmdirc.com/trunk@4820 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6.3m1rc1
Chris Smith 16 年之前
父節點
當前提交
2873a53600
共有 1 個文件被更改,包括 33 次插入2 次删除
  1. 33
    2
      src/com/dmdirc/ui/messages/Styliser.java

+ 33
- 2
src/com/dmdirc/ui/messages/Styliser.java 查看文件

56
     public static final char CODE_HYPERLINK = 5;
56
     public static final char CODE_HYPERLINK = 5;
57
     /** Character used to indicate channel links. */
57
     /** Character used to indicate channel links. */
58
     public static final char CODE_CHANNEL = 6;
58
     public static final char CODE_CHANNEL = 6;
59
+    /** Character used to indicate smilies. */
60
+    public static final char CODE_SMILIE = 7;
59
     /** The character used for stopping all formatting. */
61
     /** The character used for stopping all formatting. */
60
     public static final char CODE_STOP = 15;
62
     public static final char CODE_STOP = 15;
61
     /** Character used to indicate nickname links. */
63
     /** Character used to indicate nickname links. */
70
     public static final char CODE_UNDERLINE = 31;
72
     public static final char CODE_UNDERLINE = 31;
71
     
73
     
72
     /** Internal chars. */
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
     /** Regexp to match characters which shouldn't be used in channel links. */
78
     /** Regexp to match characters which shouldn't be used in channel links. */
76
     private static final String RESERVED_CHARS = "[^\\s" + CODE_BOLD + CODE_COLOUR
79
     private static final String RESERVED_CHARS = "[^\\s" + CODE_BOLD + CODE_COLOUR
160
                 int offset = ooffset;
163
                 int offset = ooffset;
161
                 int position = 0;
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
                 target = target.replaceAll(URL_CHANNEL, CODE_CHANNEL + "$0" + CODE_CHANNEL);
168
                 target = target.replaceAll(URL_CHANNEL, CODE_CHANNEL + "$0" + CODE_CHANNEL);
166
                 
169
                 
232
         
235
         
233
         return target;
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
      * Strips all recognised control codes from the input string.
254
      * Strips all recognised control codes from the input string.
278
         pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
295
         pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
279
         pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
296
         pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
280
         pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
297
         pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
298
+        pos = checkChar(pos, input.indexOf(CODE_SMILIE));
281
         pos = checkChar(pos, input.indexOf(CODE_NEGATE));
299
         pos = checkChar(pos, input.indexOf(CODE_NEGATE));
282
         
300
         
283
         return input.substring(0, pos);
301
         return input.substring(0, pos);
479
             toggleAttribute(attribs, "NegateControl");
497
             toggleAttribute(attribs, "NegateControl");
480
             return 1;
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
         return 0;
514
         return 0;
484
     }
515
     }

Loading…
取消
儲存