Browse Source

Merge pull request #712 from csmith/master

Move IRC control codes to their own class.
pull/713/head
Greg Holmes 7 years ago
parent
commit
d103b5ae92

+ 4
- 4
src/main/java/com/dmdirc/commandparser/commands/Command.java View File

28
 import com.dmdirc.events.CommandOutputEvent;
28
 import com.dmdirc.events.CommandOutputEvent;
29
 import com.dmdirc.interfaces.CommandController;
29
 import com.dmdirc.interfaces.CommandController;
30
 import com.dmdirc.interfaces.WindowModel;
30
 import com.dmdirc.interfaces.WindowModel;
31
-import com.dmdirc.ui.messages.Styliser;
31
+import com.dmdirc.ui.messages.IRCControlCodes;
32
 
32
 
33
 import javax.annotation.Nonnull;
33
 import javax.annotation.Nonnull;
34
 import javax.annotation.Nullable;
34
 import javax.annotation.Nullable;
104
      */
104
      */
105
     protected static String doTable(final String[] headers, final String[][] data) {
105
     protected static String doTable(final String[] headers, final String[][] data) {
106
         final StringBuilder res = new StringBuilder();
106
         final StringBuilder res = new StringBuilder();
107
-        res.append(Styliser.CODE_FIXED);
108
-        res.append(Styliser.CODE_BOLD);
107
+        res.append(IRCControlCodes.FIXED);
108
+        res.append(IRCControlCodes.BOLD);
109
 
109
 
110
         final int[] maxsizes = new int[headers.length];
110
         final int[] maxsizes = new int[headers.length];
111
 
111
 
121
 
121
 
122
         for (String[] source : data) {
122
         for (String[] source : data) {
123
             res.append('\n');
123
             res.append('\n');
124
-            res.append(Styliser.CODE_FIXED);
124
+            res.append(IRCControlCodes.FIXED);
125
 
125
 
126
             for (int i = 0; i < source.length; i++) {
126
             for (int i = 0; i < source.length; i++) {
127
                 doPadding(res, source[i], maxsizes[i]);
127
                 doPadding(res, source[i], maxsizes[i]);

+ 10
- 10
src/main/java/com/dmdirc/commandparser/commands/global/Help.java View File

33
 import com.dmdirc.interfaces.WindowModel;
33
 import com.dmdirc.interfaces.WindowModel;
34
 import com.dmdirc.ui.input.AdditionalTabTargets;
34
 import com.dmdirc.ui.input.AdditionalTabTargets;
35
 import com.dmdirc.ui.input.TabCompletionType;
35
 import com.dmdirc.ui.input.TabCompletionType;
36
-import com.dmdirc.ui.messages.Styliser;
36
+import com.dmdirc.ui.messages.IRCControlCodes;
37
 
37
 
38
 import java.util.ArrayList;
38
 import java.util.ArrayList;
39
 import java.util.Collections;
39
 import java.util.Collections;
87
 
87
 
88
         Collections.sort(commands);
88
         Collections.sort(commands);
89
 
89
 
90
-        showOutput(origin, isSilent, Styliser.CODE_FIXED
90
+        showOutput(origin, isSilent, IRCControlCodes.FIXED
91
                 + "----------------------- Available commands -------");
91
                 + "----------------------- Available commands -------");
92
 
92
 
93
         final StringBuilder builder = new StringBuilder();
93
         final StringBuilder builder = new StringBuilder();
94
 
94
 
95
         for (String command : commands) {
95
         for (String command : commands) {
96
             if (builder.length() + command.length() + 1 > 50) {
96
             if (builder.length() + command.length() + 1 > 50) {
97
-                showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
97
+                showOutput(origin, isSilent, IRCControlCodes.FIXED + builder.toString());
98
                 builder.delete(0, builder.length());
98
                 builder.delete(0, builder.length());
99
             } else if (builder.length() > 0) {
99
             } else if (builder.length() > 0) {
100
                 builder.append(' ');
100
                 builder.append(' ');
104
         }
104
         }
105
 
105
 
106
         if (builder.length() > 0) {
106
         if (builder.length() > 0) {
107
-            showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
107
+            showOutput(origin, isSilent, IRCControlCodes.FIXED + builder.toString());
108
         }
108
         }
109
 
109
 
110
-        showOutput(origin, isSilent, Styliser.CODE_FIXED
110
+        showOutput(origin, isSilent, IRCControlCodes.FIXED
111
                 + "--------------------------------------------------");
111
                 + "--------------------------------------------------");
112
     }
112
     }
113
 
113
 
131
         if (command == null) {
131
         if (command == null) {
132
             showError(origin, isSilent, "Command '" + name + "' not found.");
132
             showError(origin, isSilent, "Command '" + name + "' not found.");
133
         } else {
133
         } else {
134
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
134
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
135
                     + "---------------------- Command information -------");
135
                     + "---------------------- Command information -------");
136
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
136
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
137
                     + " Name: " + name);
137
                     + " Name: " + name);
138
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
138
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
139
                     + " Type: " + command.getKey().getType());
139
                     + " Type: " + command.getKey().getType());
140
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
140
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
141
                     + "Usage: " + command.getKey().getHelp());
141
                     + "Usage: " + command.getKey().getHelp());
142
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
142
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
143
                     + "--------------------------------------------------");
143
                     + "--------------------------------------------------");
144
         }
144
         }
145
     }
145
     }

+ 4
- 4
src/main/java/com/dmdirc/commandparser/commands/server/OpenQuery.java View File

38
 import com.dmdirc.interfaces.WindowModel;
38
 import com.dmdirc.interfaces.WindowModel;
39
 import com.dmdirc.ui.input.AdditionalTabTargets;
39
 import com.dmdirc.ui.input.AdditionalTabTargets;
40
 import com.dmdirc.ui.input.TabCompletionType;
40
 import com.dmdirc.ui.input.TabCompletionType;
41
-import com.dmdirc.ui.messages.Styliser;
41
+import com.dmdirc.ui.messages.IRCControlCodes;
42
 
42
 
43
 import javax.annotation.Nonnull;
43
 import javax.annotation.Nonnull;
44
 import javax.inject.Inject;
44
 import javax.inject.Inject;
76
         final Connection connection = ((ServerCommandContext) context).getConnection();
76
         final Connection connection = ((ServerCommandContext) context).getConnection();
77
         if (connection.getParser().get().isValidChannelName(args.getArguments()[0])) {
77
         if (connection.getParser().get().isValidChannelName(args.getArguments()[0])) {
78
             showError(origin, args.isSilent(), "You can't open a query "
78
             showError(origin, args.isSilent(), "You can't open a query "
79
-                    + "with a channel; maybe you meant " + Styliser.CODE_FIXED
80
-                    + Styliser.CODE_BOLD
79
+                    + "with a channel; maybe you meant " + IRCControlCodes.FIXED
80
+                    + IRCControlCodes.BOLD
81
                     + getController().getCommandChar()
81
                     + getController().getCommandChar()
82
                     + (args.getArguments().length > 1 ? "msg" : "join") + ' '
82
                     + (args.getArguments().length > 1 ? "msg" : "join") + ' '
83
                     + args.getArgumentsAsString()
83
                     + args.getArgumentsAsString()
84
-                    + Styliser.CODE_BOLD + Styliser.CODE_FIXED + '?');
84
+                    + IRCControlCodes.BOLD + IRCControlCodes.FIXED + '?');
85
             return;
85
             return;
86
         }
86
         }
87
 
87
 

+ 10
- 10
src/main/java/com/dmdirc/ui/input/InputHandler.java View File

40
 import com.dmdirc.plugins.ServiceManager;
40
 import com.dmdirc.plugins.ServiceManager;
41
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
41
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
42
 import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
42
 import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
43
-import com.dmdirc.ui.messages.Styliser;
43
+import com.dmdirc.ui.messages.IRCControlCodes;
44
 import com.dmdirc.util.collections.ListenerList;
44
 import com.dmdirc.util.collections.ListenerList;
45
 import com.dmdirc.util.collections.RollingList;
45
 import com.dmdirc.util.collections.RollingList;
46
 import com.dmdirc.util.validators.ValidationResponse;
46
 import com.dmdirc.util.validators.ValidationResponse;
250
             // or control code with a comma (so they can pick a background)
250
             // or control code with a comma (so they can pick a background)
251
             final String partialLine = line.substring(0, caretPosition - 1);
251
             final String partialLine = line.substring(0, caretPosition - 1);
252
 
252
 
253
-            if (partialLine.matches("^.*" + Styliser.CODE_COLOUR + "[0-9]{0,2}$")) {
253
+            if (partialLine.matches("^.*" + IRCControlCodes.COLOUR + "[0-9]{0,2}$")) {
254
                 target.showColourPicker(true, false);
254
                 target.showColourPicker(true, false);
255
-            } else if (partialLine.matches("^.*" + Styliser.CODE_HEXCOLOUR + "[0-9A-Z]{6}?$")) {
255
+            } else if (partialLine.matches("^.*" + IRCControlCodes.COLOUR_HEX + "[0-9A-Z]{6}?$")) {
256
                 target.showColourPicker(false, true);
256
                 target.showColourPicker(false, true);
257
             }
257
             }
258
         }
258
         }
399
             final boolean shiftPressed) {
399
             final boolean shiftPressed) {
400
         switch (keyCode) {
400
         switch (keyCode) {
401
             case KeyEvent.VK_B:
401
             case KeyEvent.VK_B:
402
-                addControlCode(Styliser.CODE_BOLD, POSITION_END);
402
+                addControlCode(IRCControlCodes.BOLD, POSITION_END);
403
                 break;
403
                 break;
404
 
404
 
405
             case KeyEvent.VK_U:
405
             case KeyEvent.VK_U:
406
-                addControlCode(Styliser.CODE_UNDERLINE, POSITION_END);
406
+                addControlCode(IRCControlCodes.UNDERLINE, POSITION_END);
407
                 break;
407
                 break;
408
 
408
 
409
             case KeyEvent.VK_O:
409
             case KeyEvent.VK_O:
410
-                addControlCode(Styliser.CODE_STOP, POSITION_END);
410
+                addControlCode(IRCControlCodes.STOP, POSITION_END);
411
                 break;
411
                 break;
412
 
412
 
413
             case KeyEvent.VK_I:
413
             case KeyEvent.VK_I:
414
-                addControlCode(Styliser.CODE_ITALIC, POSITION_END);
414
+                addControlCode(IRCControlCodes.ITALIC, POSITION_END);
415
                 break;
415
                 break;
416
 
416
 
417
             case KeyEvent.VK_F:
417
             case KeyEvent.VK_F:
418
                 if (shiftPressed) {
418
                 if (shiftPressed) {
419
-                    addControlCode(Styliser.CODE_FIXED, POSITION_END);
419
+                    addControlCode(IRCControlCodes.FIXED, POSITION_END);
420
                 }
420
                 }
421
                 break;
421
                 break;
422
 
422
 
423
             case KeyEvent.VK_K:
423
             case KeyEvent.VK_K:
424
                 if (shiftPressed) {
424
                 if (shiftPressed) {
425
-                    addControlCode(Styliser.CODE_HEXCOLOUR, POSITION_START);
425
+                    addControlCode(IRCControlCodes.COLOUR_HEX, POSITION_START);
426
                     target.showColourPicker(false, true);
426
                     target.showColourPicker(false, true);
427
                 } else {
427
                 } else {
428
-                    addControlCode(Styliser.CODE_COLOUR, POSITION_START);
428
+                    addControlCode(IRCControlCodes.COLOUR, POSITION_START);
429
                     target.showColourPicker(true, false);
429
                     target.showColourPicker(true, false);
430
                 }
430
                 }
431
                 break;
431
                 break;

+ 47
- 0
src/main/java/com/dmdirc/ui/messages/IRCControlCodes.java View File

1
+/*
2
+ * Copyright (c) 2006-2016 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.messages;
24
+
25
+/**
26
+ * Contains constants for IRC 'control codes' that modify text styles.
27
+ */
28
+public interface IRCControlCodes {
29
+
30
+  /** The character used for marking up bold text. */
31
+  char BOLD = 2;
32
+  /** The character used for marking up coloured text. */
33
+  char COLOUR = 3;
34
+  /** The character used for marking up coloured text (using hex). */
35
+  char COLOUR_HEX = 4;
36
+  /** The character used for stopping all formatting. */
37
+  char STOP = 15;
38
+  /** The character used for marking up fixed pitch text. */
39
+  char FIXED = 17;
40
+  /** The character used for negating control codes. */
41
+  char NEGATE = 18;
42
+  /** The character used for marking up italic text. */
43
+  char ITALIC = 29;
44
+  /** The character used for marking up underlined text. */
45
+  char UNDERLINE = 31;
46
+
47
+}

+ 2
- 1
src/main/java/com/dmdirc/ui/messages/IRCLine.java View File

105
     @Override
105
     @Override
106
     public <T> T getStyled(final StyledMessageMaker<T> maker) {
106
     public <T> T getStyled(final StyledMessageMaker<T> maker) {
107
         maker.setDefaultFont(fontName, fontSize);
107
         maker.setDefaultFont(fontName, fontSize);
108
-        final T styledString = styliser.getStyledString(getLineParts(), maker);
108
+        styliser.addStyledString(maker, getLineParts());;
109
+        final T styledString = maker.getStyledMessage();
109
         fontSize = maker.getMaximumFontSize();
110
         fontSize = maker.getMaximumFontSize();
110
         maker.clear();
111
         maker.clear();
111
         return styledString;
112
         return styledString;

+ 35
- 64
src/main/java/com/dmdirc/ui/messages/Styliser.java View File

22
 
22
 
23
 package com.dmdirc.ui.messages;
23
 package com.dmdirc.ui.messages;
24
 
24
 
25
+import static com.google.common.base.Preconditions.checkArgument;
26
+
25
 import com.dmdirc.interfaces.Connection;
27
 import com.dmdirc.interfaces.Connection;
26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27
 import com.dmdirc.interfaces.config.ConfigChangeListener;
29
 import com.dmdirc.interfaces.config.ConfigChangeListener;
28
 import com.dmdirc.util.colours.Colour;
30
 import com.dmdirc.util.colours.Colour;
29
-
30
 import java.util.Locale;
31
 import java.util.Locale;
31
 import java.util.regex.Pattern;
32
 import java.util.regex.Pattern;
32
-
33
 import javax.annotation.Nullable;
33
 import javax.annotation.Nullable;
34
 
34
 
35
-import static com.google.common.base.Preconditions.checkArgument;
36
-
37
 /**
35
 /**
38
  * The styliser applies IRC styles to text. Styles are indicated by various control codes which are
36
  * The styliser applies IRC styles to text. Styles are indicated by various control codes which are
39
  * a de-facto IRC standard.
37
  * a de-facto IRC standard.
40
  */
38
  */
41
 public class Styliser implements ConfigChangeListener {
39
 public class Styliser implements ConfigChangeListener {
42
 
40
 
43
-    /** The character used for marking up bold text. */
44
-    public static final char CODE_BOLD = 2;
45
-    /** The character used for marking up coloured text. */
46
-    public static final char CODE_COLOUR = 3;
47
-    /** The character used for marking up coloured text (using hex). */
48
-    public static final char CODE_HEXCOLOUR = 4;
49
     /** Character used to indicate hyperlinks. */
41
     /** Character used to indicate hyperlinks. */
50
     public static final char CODE_HYPERLINK = 5;
42
     public static final char CODE_HYPERLINK = 5;
51
     /** Character used to indicate channel links. */
43
     /** Character used to indicate channel links. */
52
     public static final char CODE_CHANNEL = 6;
44
     public static final char CODE_CHANNEL = 6;
53
     /** Character used to indicate smilies. */
45
     /** Character used to indicate smilies. */
54
     public static final char CODE_SMILIE = 7;
46
     public static final char CODE_SMILIE = 7;
55
-    /** The character used for stopping all formatting. */
56
-    public static final char CODE_STOP = 15;
57
     /** Character used to indicate nickname links. */
47
     /** Character used to indicate nickname links. */
58
     public static final char CODE_NICKNAME = 16;
48
     public static final char CODE_NICKNAME = 16;
59
-    /** The character used for marking up fixed pitch text. */
60
-    public static final char CODE_FIXED = 17;
61
-    /** The character used for negating control codes. */
62
-    public static final char CODE_NEGATE = 18;
63
     /** The character used for tooltips. */
49
     /** The character used for tooltips. */
64
     public static final char CODE_TOOLTIP = 19;
50
     public static final char CODE_TOOLTIP = 19;
65
-    /** The character used for marking up italic text. */
66
-    public static final char CODE_ITALIC = 29;
67
-    /** The character used for marking up underlined text. */
68
-    public static final char CODE_UNDERLINE = 31;
69
     /** Internal chars. */
51
     /** Internal chars. */
70
     private static final String INTERNAL_CHARS = String.valueOf(CODE_HYPERLINK)
52
     private static final String INTERNAL_CHARS = String.valueOf(CODE_HYPERLINK)
71
             + CODE_NICKNAME + CODE_CHANNEL + CODE_SMILIE + CODE_TOOLTIP;
53
             + CODE_NICKNAME + CODE_CHANNEL + CODE_SMILIE + CODE_TOOLTIP;
72
     /** Characters used for hyperlinks. */
54
     /** Characters used for hyperlinks. */
73
     private static final String HYPERLINK_CHARS = Character.toString(CODE_HYPERLINK) + CODE_CHANNEL;
55
     private static final String HYPERLINK_CHARS = Character.toString(CODE_HYPERLINK) + CODE_CHANNEL;
74
     /** Regexp to match characters which shouldn't be used in channel links. */
56
     /** Regexp to match characters which shouldn't be used in channel links. */
75
-    private static final String RESERVED_CHARS = "[^\\s" + CODE_BOLD + CODE_COLOUR
76
-            + CODE_STOP + CODE_HEXCOLOUR + CODE_FIXED + CODE_ITALIC
77
-            + CODE_UNDERLINE + CODE_CHANNEL + CODE_NICKNAME + CODE_NEGATE + "\",]";
57
+    private static final String RESERVED_CHARS = "[^\\s" + IRCControlCodes.BOLD + IRCControlCodes.COLOUR
58
+            + IRCControlCodes.STOP + IRCControlCodes.COLOUR_HEX + IRCControlCodes.FIXED + IRCControlCodes.ITALIC
59
+            + IRCControlCodes.UNDERLINE + CODE_CHANNEL + CODE_NICKNAME + IRCControlCodes.NEGATE
60
+        + "\",]";
78
     /** Defines all characters treated as trailing punctuation that are illegal in URLs. */
61
     /** Defines all characters treated as trailing punctuation that are illegal in URLs. */
79
     private static final String URL_PUNCT_ILLEGAL = "\"";
62
     private static final String URL_PUNCT_ILLEGAL = "\"";
80
     /** Defines all characters treated as trailing punctuation that're legal in URLs. */
63
     /** Defines all characters treated as trailing punctuation that're legal in URLs. */
87
     private static final String URL_CHARS = '[' + URL_PUNCT_LEGAL + URL_NOPUNCT
70
     private static final String URL_CHARS = '[' + URL_PUNCT_LEGAL + URL_NOPUNCT
88
             + "]*[" + URL_NOPUNCT + "]+[" + URL_PUNCT_LEGAL + URL_NOPUNCT + "]*";
71
             + "]*[" + URL_NOPUNCT + "]+[" + URL_PUNCT_LEGAL + URL_NOPUNCT + "]*";
89
     /** The regular expression to use for marking up URLs. */
72
     /** The regular expression to use for marking up URLs. */
90
-    private static final String URL_REGEXP = "(?i)((?>(?<!" + CODE_HEXCOLOUR
73
+    private static final String URL_REGEXP = "(?i)((?>(?<!" + IRCControlCodes.COLOUR_HEX
91
             + "[a-f0-9]{5})[a-f]|[g-z+])+://" + URL_CHARS
74
             + "[a-f0-9]{5})[a-f]|[g-z+])+://" + URL_CHARS
92
             + "|(?<![a-z0-9:/])www\\." + URL_CHARS + ')';
75
             + "|(?<![a-z0-9:/])www\\." + URL_CHARS + ')';
93
     /** Regular expression for intelligent handling of closing brackets. */
76
     /** Regular expression for intelligent handling of closing brackets. */
191
         }
174
         }
192
     }
175
     }
193
 
176
 
194
-    /**
195
-     * Stylises the specified string.
196
-     *
197
-     * @param strings The line to be stylised
198
-     *
199
-     * @return StyledDocument for the inputted strings
200
-     */
201
-    public <T> T getStyledString(final String[] strings, final StyledMessageMaker<T> maker) {
202
-        addStyledString(maker, strings);
203
-        return maker.getStyledMessage();
204
-    }
205
-
206
     /**
177
     /**
207
      * Retrieves the styled String contained within the unstyled offsets specified. That is, the
178
      * Retrieves the styled String contained within the unstyled offsets specified. That is, the
208
      * <code>from</code> and <code>to</code> arguments correspond to indexes in an unstyled version
179
      * <code>from</code> and <code>to</code> arguments correspond to indexes in an unstyled version
293
      *
264
      *
294
      * @since 0.6.3m1
265
      * @since 0.6.3m1
295
      */
266
      */
296
-    public String doSmilies(final String string) {
267
+    private String doSmilies(final String string) {
297
         // TODO: Check if they're enabled.
268
         // TODO: Check if they're enabled.
298
         // TODO: Store the list instead of building it every line
269
         // TODO: Store the list instead of building it every line
299
 
270
 
320
      * @return a copy of the input with control codes removed
291
      * @return a copy of the input with control codes removed
321
      */
292
      */
322
     public static String stipControlCodes(final String input) {
293
     public static String stipControlCodes(final String input) {
323
-        return input.replaceAll("[" + CODE_BOLD + CODE_CHANNEL + CODE_FIXED
324
-                + CODE_HYPERLINK + CODE_ITALIC + CODE_NEGATE + CODE_NICKNAME
325
-                + CODE_SMILIE + CODE_STOP + CODE_UNDERLINE + "]|"
326
-                + CODE_HEXCOLOUR + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
327
-                + CODE_COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
294
+        return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
295
+                + CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE + CODE_NICKNAME
296
+                + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
297
+                + IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
298
+                + IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
328
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
299
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
329
     }
300
     }
330
 
301
 
337
      *
308
      *
338
      * @since 0.6.5
309
      * @since 0.6.5
339
      */
310
      */
340
-    public static String stipInternalControlCodes(final String input) {
311
+    private static String stipInternalControlCodes(final String input) {
341
         return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
312
         return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
342
-                + CODE_SMILIE + CODE_STOP + CODE_UNDERLINE + ']', "")
313
+                + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
343
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
314
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
344
                         + CODE_TOOLTIP, "$1");
315
                         + CODE_TOOLTIP, "$1");
345
     }
316
     }
356
     public static String readUntilControl(final String input) {
327
     public static String readUntilControl(final String input) {
357
         int pos = input.length();
328
         int pos = input.length();
358
 
329
 
359
-        pos = checkChar(pos, input.indexOf(CODE_BOLD));
360
-        pos = checkChar(pos, input.indexOf(CODE_UNDERLINE));
361
-        pos = checkChar(pos, input.indexOf(CODE_STOP));
362
-        pos = checkChar(pos, input.indexOf(CODE_COLOUR));
363
-        pos = checkChar(pos, input.indexOf(CODE_HEXCOLOUR));
364
-        pos = checkChar(pos, input.indexOf(CODE_ITALIC));
365
-        pos = checkChar(pos, input.indexOf(CODE_FIXED));
330
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.BOLD));
331
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.UNDERLINE));
332
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.STOP));
333
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.COLOUR));
334
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.COLOUR_HEX));
335
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.ITALIC));
336
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.FIXED));
366
         pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
337
         pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
367
         pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
338
         pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
368
         pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
339
         pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
369
         pos = checkChar(pos, input.indexOf(CODE_SMILIE));
340
         pos = checkChar(pos, input.indexOf(CODE_SMILIE));
370
-        pos = checkChar(pos, input.indexOf(CODE_NEGATE));
341
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.NEGATE));
371
         pos = checkChar(pos, input.indexOf(CODE_TOOLTIP));
342
         pos = checkChar(pos, input.indexOf(CODE_TOOLTIP));
372
 
343
 
373
         return input.substring(0, pos);
344
         return input.substring(0, pos);
404
         final boolean isNegated = state.isNegated;
375
         final boolean isNegated = state.isNegated;
405
 
376
 
406
         // Bold
377
         // Bold
407
-        if (string.charAt(0) == CODE_BOLD) {
378
+        if (string.charAt(0) == IRCControlCodes.BOLD) {
408
             if (!isNegated) {
379
             if (!isNegated) {
409
                 maker.toggleBold();
380
                 maker.toggleBold();
410
             }
381
             }
413
         }
384
         }
414
 
385
 
415
         // Underline
386
         // Underline
416
-        if (string.charAt(0) == CODE_UNDERLINE) {
387
+        if (string.charAt(0) == IRCControlCodes.UNDERLINE) {
417
             if (!isNegated) {
388
             if (!isNegated) {
418
                 maker.toggleUnderline();
389
                 maker.toggleUnderline();
419
             }
390
             }
422
         }
393
         }
423
 
394
 
424
         // Italic
395
         // Italic
425
-        if (string.charAt(0) == CODE_ITALIC) {
396
+        if (string.charAt(0) == IRCControlCodes.ITALIC) {
426
             if (!isNegated) {
397
             if (!isNegated) {
427
                 maker.toggleItalic();
398
                 maker.toggleItalic();
428
             }
399
             }
475
         }
446
         }
476
 
447
 
477
         // Fixed pitch
448
         // Fixed pitch
478
-        if (string.charAt(0) == CODE_FIXED) {
449
+        if (string.charAt(0) == IRCControlCodes.FIXED) {
479
             if (!isNegated) {
450
             if (!isNegated) {
480
                 maker.toggleFixedWidth();
451
                 maker.toggleFixedWidth();
481
             }
452
             }
484
         }
455
         }
485
 
456
 
486
         // Stop formatting
457
         // Stop formatting
487
-        if (string.charAt(0) == CODE_STOP) {
458
+        if (string.charAt(0) == IRCControlCodes.STOP) {
488
             if (!isNegated) {
459
             if (!isNegated) {
489
                 maker.resetAllStyles();
460
                 maker.resetAllStyles();
490
             }
461
             }
493
         }
464
         }
494
 
465
 
495
         // Colours
466
         // Colours
496
-        if (string.charAt(0) == CODE_COLOUR) {
467
+        if (string.charAt(0) == IRCControlCodes.COLOUR) {
497
             int count = 1;
468
             int count = 1;
498
             // This isn't too nice!
469
             // This isn't too nice!
499
             if (string.length() > count && isInt(string.charAt(count))) {
470
             if (string.length() > count && isInt(string.charAt(count))) {
542
         }
513
         }
543
 
514
 
544
         // Hex colours
515
         // Hex colours
545
-        if (string.charAt(0) == CODE_HEXCOLOUR) {
516
+        if (string.charAt(0) == IRCControlCodes.COLOUR_HEX) {
546
             int count = 1;
517
             int count = 1;
547
             if (hasHexString(string, 1)) {
518
             if (hasHexString(string, 1)) {
548
                 if (!isNegated) {
519
                 if (!isNegated) {
583
         }
554
         }
584
 
555
 
585
         // Control code negation
556
         // Control code negation
586
-        if (string.charAt(0) == CODE_NEGATE) {
557
+        if (string.charAt(0) == IRCControlCodes.NEGATE) {
587
             state.isNegated = !state.isNegated;
558
             state.isNegated = !state.isNegated;
588
             return 1;
559
             return 1;
589
         }
560
         }
692
 
663
 
693
     private static class StyliserState {
664
     private static class StyliserState {
694
 
665
 
695
-        public boolean isNegated;
696
-        public boolean isInLink;
697
-        public boolean isInSmilie;
698
-        public boolean isInToolTip;
666
+        boolean isNegated;
667
+        boolean isInLink;
668
+        boolean isInSmilie;
669
+        boolean isInToolTip;
699
 
670
 
700
     }
671
     }
701
 
672
 

+ 7
- 7
src/test/java/com/dmdirc/ui/messages/StyliserIndicesTest.java View File

55
             // No style
55
             // No style
56
             {"Blah blah blah", 0, 1, "B"},
56
             {"Blah blah blah", 0, 1, "B"},
57
             {"Blah blah blah", 0, 4, "Blah"},
57
             {"Blah blah blah", 0, 4, "Blah"},
58
-            {Styliser.CODE_BOLD + "Blah blah blah", 0, 4, Styliser.CODE_BOLD + "Blah"},
59
-            {Styliser.CODE_BOLD + "Bl" + Styliser.CODE_BOLD + "ah blah blah",
60
-                     0, 4, Styliser.CODE_BOLD + "Bl" + Styliser.CODE_BOLD + "ah"},
61
-            {"Blah" + Styliser.CODE_BOLD + " blah blah",
58
+            {IRCControlCodes.BOLD + "Blah blah blah", 0, 4, IRCControlCodes.BOLD + "Blah"},
59
+            {IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah blah blah",
60
+                     0, 4, IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah"},
61
+            {"Blah" + IRCControlCodes.BOLD + " blah blah",
62
                      0, 4, "Blah"},
62
                      0, 4, "Blah"},
63
-            {"Blah" + Styliser.CODE_COLOUR + "4,0RED blah blah",
64
-                     4, 7, Styliser.CODE_COLOUR + "4,0RED"},
65
-            {"Blah" + Styliser.CODE_COLOUR + "4,0RED blah blah",
63
+            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
64
+                     4, 7, IRCControlCodes.COLOUR + "4,0RED"},
65
+            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
66
                      5, 7, "ED"},
66
                      5, 7, "ED"},
67
             {Styliser.CODE_TOOLTIP + "Annoying internal tooltip text"
67
             {Styliser.CODE_TOOLTIP + "Annoying internal tooltip text"
68
                      + Styliser.CODE_TOOLTIP + "Blah" + Styliser.CODE_TOOLTIP + "Blah",
68
                      + Styliser.CODE_TOOLTIP + "Blah" + Styliser.CODE_TOOLTIP + "Blah",

Loading…
Cancel
Save