Skip to content

Commit

Permalink
Merge pull request #723 from csmith/styliser
Browse files Browse the repository at this point in the history
Remove deprecated styliser methods.
  • Loading branch information
greboid committed Dec 24, 2016
2 parents a84a298 + 9158422 commit 719e31a
Showing 1 changed file with 0 additions and 88 deletions.
88 changes: 0 additions & 88 deletions src/main/java/com/dmdirc/ui/messages/Styliser.java
Expand Up @@ -31,8 +31,6 @@
import java.util.regex.Pattern;
import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;

/**
* The styliser applies IRC styles to text. Styles are indicated by various control codes which are
* a de-facto IRC standard.
Expand Down Expand Up @@ -175,57 +173,6 @@ public void addStyledString(final StyledMessageMaker<?> maker, final String... s
}
}

/**
* Retrieves the styled String contained within the unstyled offsets specified. That is, the
* <code>from</code> and <code>to</code> arguments correspond to indexes in an unstyled version
* of the <code>styled</code> string. The unstyled indices are translated to offsets within the
* styled String, and the return value includes all text and control codes between those
* indices.
* <p>
* The index translation is left-biased; that is, the indices are translated to be as far left
* as they possibly can be. This means that the start of the string will include any control
* codes immediately preceding the desired text, and the end will not include any trailing
* codes.
* <p>
* This method will NOT include "internal" control codes in the output.
*
* @param styled The styled String to be operated on
* @param from The starting index in the unstyled string
* @param to The ending index in the unstyled string
*
* @return The corresponding text between the two indices
*
* @since 0.6.3
* @deprecated Use {@link StyledMessageUtils}
*/
@Deprecated
public static String getStyledText(final String styled, final int from, final int to) {
checkArgument(from < to, "'from' (" + from + ") must be less than 'to' (" + to + ')');
checkArgument(from >= 0, "'from' (" + from + ") must be non-negative");

final String unstyled = stipControlCodes(styled);

checkArgument(to <= unstyled.length(), "'to' (" + to + ") must be less than or equal to "
+ "the unstyled length (" + unstyled.length() + ')');

final String startBit = unstyled.substring(0, from);
final String middleBit = unstyled.substring(from, to);
final String sanitised = stipInternalControlCodes(styled);
int start = from;

while (!stipControlCodes(sanitised.substring(0, start)).equals(startBit)) {
start++;
}

int end = to + start - from;

while (!stipControlCodes(sanitised.substring(start, end)).equals(middleBit)) {
end++;
}

return sanitised.substring(start, end);
}

/**
* Applies the hyperlink styles and intelligent linking regexps to the target.
*
Expand Down Expand Up @@ -286,41 +233,6 @@ private String doSmilies(final String string) {
"$1" + CODE_SMILIE + "$2" + CODE_SMILIE);
}

/**
* Strips all recognised control codes from the input string.
*
* @param input the String to be stripped
*
* @return a copy of the input with control codes removed
* @deprecated Use {@link StyledMessageUtils}
*/
@Deprecated
public static String stipControlCodes(final String input) {
return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
+ CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE + CODE_NICKNAME
+ CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
+ IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
+ IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
.replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
}

/**
* St(r)ips all recognised internal control codes from the input string.
*
* @param input the String to be stripped
*
* @return a copy of the input with control codes removed
*
* @since 0.6.5
*/
@Deprecated
private static String stipInternalControlCodes(final String input) {
return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
+ CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
.replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
+ CODE_TOOLTIP, "$1");
}

/**
* Returns a substring of the input string such that no control codes are present in the output.
* If the returned value isn't the same as the input, then the character immediately after is a
Expand Down

0 comments on commit 719e31a

Please sign in to comment.