|
@@ -251,6 +251,8 @@ public class Styliser implements ConfigChangeListener {
|
251
|
251
|
* to be as far left as they possibly can be. This means that the start of
|
252
|
252
|
* the string will include any control codes immediately preceeding the
|
253
|
253
|
* desired text, and the end will not include any trailing codes.
|
|
254
|
+ * <p>
|
|
255
|
+ * This method will NOT include "internal" control codes in the output.
|
254
|
256
|
*
|
255
|
257
|
* @param styled The styled String to be operated on
|
256
|
258
|
* @param from The starting index in the unstyled string
|
|
@@ -262,19 +264,20 @@ public class Styliser implements ConfigChangeListener {
|
262
|
264
|
final String unstyled = stipControlCodes(styled);
|
263
|
265
|
final String startBit = unstyled.substring(0, from);
|
264
|
266
|
final String middleBit = unstyled.substring(from, to);
|
|
267
|
+ final String sanitised = stipInternalControlCodes(styled);
|
265
|
268
|
int start = from;
|
266
|
269
|
|
267
|
|
- while (!stipControlCodes(styled.substring(0, start)).equals(startBit)) {
|
|
270
|
+ while (!stipControlCodes(sanitised.substring(0, start)).equals(startBit)) {
|
268
|
271
|
start++;
|
269
|
272
|
}
|
270
|
273
|
|
271
|
274
|
int end = to + start - from;
|
272
|
275
|
|
273
|
|
- while (!stipControlCodes(styled.substring(start, end)).equals(middleBit)) {
|
|
276
|
+ while (!stipControlCodes(sanitised.substring(start, end)).equals(middleBit)) {
|
274
|
277
|
end++;
|
275
|
278
|
}
|
276
|
279
|
|
277
|
|
- return styled.substring(start, end);
|
|
280
|
+ return sanitised.substring(start, end);
|
278
|
281
|
}
|
279
|
282
|
|
280
|
283
|
/**
|
|
@@ -352,6 +355,20 @@ public class Styliser implements ConfigChangeListener {
|
352
|
355
|
+ CODE_TOOLTIP, "$1");
|
353
|
356
|
}
|
354
|
357
|
|
|
358
|
+ /**
|
|
359
|
+ * St(r)ips all recognised internal control codes from the input string.
|
|
360
|
+ *
|
|
361
|
+ * @param input the String to be stripped
|
|
362
|
+ * @return a copy of the input with control codes removed
|
|
363
|
+ * @since 0.6.5
|
|
364
|
+ */
|
|
365
|
+ public static String stipInternalControlCodes(final String input) {
|
|
366
|
+ return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
|
|
367
|
+ + CODE_SMILIE + CODE_STOP + CODE_UNDERLINE + "]", "")
|
|
368
|
+ .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
|
|
369
|
+ + CODE_TOOLTIP, "$1");
|
|
370
|
+ }
|
|
371
|
+
|
355
|
372
|
/**
|
356
|
373
|
* Returns a substring of the input string such that no control codes are present
|
357
|
374
|
* in the output. If the returned value isn't the same as the input, then the
|