|
@@ -31,8 +31,6 @@ import java.util.Locale;
|
31
|
31
|
import java.util.regex.Pattern;
|
32
|
32
|
import javax.annotation.Nullable;
|
33
|
33
|
|
34
|
|
-import static com.google.common.base.Preconditions.checkArgument;
|
35
|
|
-
|
36
|
34
|
/**
|
37
|
35
|
* The styliser applies IRC styles to text. Styles are indicated by various control codes which are
|
38
|
36
|
* a de-facto IRC standard.
|
|
@@ -175,57 +173,6 @@ public class Styliser implements ConfigChangeListener {
|
175
|
173
|
}
|
176
|
174
|
}
|
177
|
175
|
|
178
|
|
- /**
|
179
|
|
- * Retrieves the styled String contained within the unstyled offsets specified. That is, the
|
180
|
|
- * <code>from</code> and <code>to</code> arguments correspond to indexes in an unstyled version
|
181
|
|
- * of the <code>styled</code> string. The unstyled indices are translated to offsets within the
|
182
|
|
- * styled String, and the return value includes all text and control codes between those
|
183
|
|
- * indices.
|
184
|
|
- * <p>
|
185
|
|
- * The index translation is left-biased; that is, the indices are translated to be as far left
|
186
|
|
- * as they possibly can be. This means that the start of the string will include any control
|
187
|
|
- * codes immediately preceding the desired text, and the end will not include any trailing
|
188
|
|
- * codes.
|
189
|
|
- * <p>
|
190
|
|
- * This method will NOT include "internal" control codes in the output.
|
191
|
|
- *
|
192
|
|
- * @param styled The styled String to be operated on
|
193
|
|
- * @param from The starting index in the unstyled string
|
194
|
|
- * @param to The ending index in the unstyled string
|
195
|
|
- *
|
196
|
|
- * @return The corresponding text between the two indices
|
197
|
|
- *
|
198
|
|
- * @since 0.6.3
|
199
|
|
- * @deprecated Use {@link StyledMessageUtils}
|
200
|
|
- */
|
201
|
|
- @Deprecated
|
202
|
|
- public static String getStyledText(final String styled, final int from, final int to) {
|
203
|
|
- checkArgument(from < to, "'from' (" + from + ") must be less than 'to' (" + to + ')');
|
204
|
|
- checkArgument(from >= 0, "'from' (" + from + ") must be non-negative");
|
205
|
|
-
|
206
|
|
- final String unstyled = stipControlCodes(styled);
|
207
|
|
-
|
208
|
|
- checkArgument(to <= unstyled.length(), "'to' (" + to + ") must be less than or equal to "
|
209
|
|
- + "the unstyled length (" + unstyled.length() + ')');
|
210
|
|
-
|
211
|
|
- final String startBit = unstyled.substring(0, from);
|
212
|
|
- final String middleBit = unstyled.substring(from, to);
|
213
|
|
- final String sanitised = stipInternalControlCodes(styled);
|
214
|
|
- int start = from;
|
215
|
|
-
|
216
|
|
- while (!stipControlCodes(sanitised.substring(0, start)).equals(startBit)) {
|
217
|
|
- start++;
|
218
|
|
- }
|
219
|
|
-
|
220
|
|
- int end = to + start - from;
|
221
|
|
-
|
222
|
|
- while (!stipControlCodes(sanitised.substring(start, end)).equals(middleBit)) {
|
223
|
|
- end++;
|
224
|
|
- }
|
225
|
|
-
|
226
|
|
- return sanitised.substring(start, end);
|
227
|
|
- }
|
228
|
|
-
|
229
|
176
|
/**
|
230
|
177
|
* Applies the hyperlink styles and intelligent linking regexps to the target.
|
231
|
178
|
*
|
|
@@ -286,41 +233,6 @@ public class Styliser implements ConfigChangeListener {
|
286
|
233
|
"$1" + CODE_SMILIE + "$2" + CODE_SMILIE);
|
287
|
234
|
}
|
288
|
235
|
|
289
|
|
- /**
|
290
|
|
- * Strips all recognised control codes from the input string.
|
291
|
|
- *
|
292
|
|
- * @param input the String to be stripped
|
293
|
|
- *
|
294
|
|
- * @return a copy of the input with control codes removed
|
295
|
|
- * @deprecated Use {@link StyledMessageUtils}
|
296
|
|
- */
|
297
|
|
- @Deprecated
|
298
|
|
- public static String stipControlCodes(final String input) {
|
299
|
|
- return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
|
300
|
|
- + CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE + CODE_NICKNAME
|
301
|
|
- + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
|
302
|
|
- + IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
|
303
|
|
- + IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
|
304
|
|
- .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
|
305
|
|
- }
|
306
|
|
-
|
307
|
|
- /**
|
308
|
|
- * St(r)ips all recognised internal control codes from the input string.
|
309
|
|
- *
|
310
|
|
- * @param input the String to be stripped
|
311
|
|
- *
|
312
|
|
- * @return a copy of the input with control codes removed
|
313
|
|
- *
|
314
|
|
- * @since 0.6.5
|
315
|
|
- */
|
316
|
|
- @Deprecated
|
317
|
|
- private static String stipInternalControlCodes(final String input) {
|
318
|
|
- return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
|
319
|
|
- + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
|
320
|
|
- .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
|
321
|
|
- + CODE_TOOLTIP, "$1");
|
322
|
|
- }
|
323
|
|
-
|
324
|
236
|
/**
|
325
|
237
|
* Returns a substring of the input string such that no control codes are present in the output.
|
326
|
238
|
* If the returned value isn't the same as the input, then the character immediately after is a
|