diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-05-16 18:12:48 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-05-16 18:42:39 -0500 |
commit | f4bee983b04bad80b1c66ac45c46f1e571194486 (patch) | |
tree | 1475a56396e8f397ebb1c1e6485c6f841bb8ceed /src/test/java | |
parent | 5a7f09f1a7a77a9a9d6e9370a4efe35ee69bc844 (diff) | |
download | bukkit-f4bee983b04bad80b1c66ac45c46f1e571194486.tar bukkit-f4bee983b04bad80b1c66ac45c46f1e571194486.tar.gz bukkit-f4bee983b04bad80b1c66ac45c46f1e571194486.tar.lz bukkit-f4bee983b04bad80b1c66ac45c46f1e571194486.tar.xz bukkit-f4bee983b04bad80b1c66ac45c46f1e571194486.zip |
Optimize ChatColor.getLastColors.
ChatColor searches from the start to the end of a string for chat format
characters but this always has to search the entire string. By starting
from the end of the string and working backwards we can stop searching once
we find a color code or a reset code as any previous formatting is wiped
out by these.
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/bukkit/ChatColorTest.java | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/ChatColorTest.java b/src/test/java/org/bukkit/ChatColorTest.java index ed700020..80108a5d 100644 --- a/src/test/java/org/bukkit/ChatColorTest.java +++ b/src/test/java/org/bukkit/ChatColorTest.java @@ -70,4 +70,14 @@ public class ChatColorTest { String u = ChatColor.BLACK.toString() + ChatColor.DARK_BLUE + ChatColor.DARK_GREEN + ChatColor.DARK_AQUA + ChatColor.DARK_RED + ChatColor.DARK_PURPLE + ChatColor.GOLD + ChatColor.GRAY + ChatColor.DARK_GRAY + ChatColor.BLUE + ChatColor.GREEN + ChatColor.GREEN + ChatColor.AQUA + ChatColor.AQUA + ChatColor.RED + ChatColor.RED + ChatColor.LIGHT_PURPLE + ChatColor.LIGHT_PURPLE + ChatColor.YELLOW + ChatColor.YELLOW + ChatColor.WHITE + ChatColor.WHITE + ChatColor.MAGIC + ChatColor.MAGIC + " & more"; assertThat(t, is(u)); } + + @Test + public void getChatColors() { + String s = String.format("%c%ctest%c%ctest%c", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.ITALIC.getChar(), ChatColor.COLOR_CHAR); + String expected = ChatColor.RED.toString() + ChatColor.ITALIC; + assertThat(ChatColor.getLastColors(s), is(expected)); + + s = String.format("%c%ctest%c%ctest", ChatColor.COLOR_CHAR, ChatColor.RED.getChar(), ChatColor.COLOR_CHAR, ChatColor.BLUE.getChar()); + assertThat(ChatColor.getLastColors(s), is(ChatColor.BLUE.toString())); + } } |