Warp around color codes so that it is always possible to find a color in

the Colors array.
fix-message-formatting
Danny van Heumen 12 years ago
parent b41a7b7b04
commit 44cdb68217

@ -144,6 +144,7 @@ private static Color parseBackgroundColor(final String text)
// if available, also parse background color
int color =
Integer.parseInt("" + text.charAt(1) + text.charAt(2));
color = color % Color.values().length;
return Color.values()[color];
}
throw new IllegalArgumentException(
@ -184,6 +185,7 @@ private static Color parseForegroundColor(final String text)
try
{
int color = Integer.parseInt("" + text.charAt(0) + text.charAt(1));
color = color % Color.values().length;
return Color.values()[color];
}
catch (StringIndexOutOfBoundsException e)
@ -196,7 +198,6 @@ private static Color parseForegroundColor(final String text)
catch (NumberFormatException e)
{
// FIXME correctly print out color code (as a number or hex number)
// FIXME wrap around color codes?
// Invalid text color value
LOGGER.trace("Invalid foreground color code encountered.");
throw new IllegalArgumentException(

@ -143,14 +143,15 @@ public void testParseStringWithUnclosedFormattingI()
public void testParseUnknownForegroundColor()
{
final String ircMessage = "\u000399TEST";
final String htmlMessage = "99TEST";
final String htmlMessage = "<font color=\"Green\">TEST</font>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
}
public void testParseUnknownBackgroundColor()
{
final String ircMessage = "\u000300,99TEST";
final String htmlMessage = "<font color=\"White\">,99TEST</font>";
final String htmlMessage =
"<font color=\"White\" bgcolor=\"Green\">TEST</font>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
}

Loading…
Cancel
Save