From 1701140aa6829c8282fc11a2f8cecb782ac44ed0 Mon Sep 17 00:00:00 2001 From: brainage04 <101778999+brainage04@users.noreply.github.com> Date: Sat, 23 Sep 2023 20:49:53 +1000 Subject: Small performance improvements when working with color codes #489 * more efficient implementation of String.removeColor() --- .../java/at/hannibal2/skyhanni/utils/StringUtils.kt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 8150bce4f..7a7eeeb60 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -19,20 +19,17 @@ object StringUtils { } fun String.removeColor(): String { -// return replace("(?i)\\u00A7.", "") - val builder = StringBuilder() - var skipNext = false - for (c in this.toCharArray()) { - if (c == '§') { - skipNext = true - continue - } - if (skipNext) { - skipNext = false + + var counter = 0 + while (counter < this.length) { + if (this[counter] == '§') { + counter += 2 continue + } else { + builder.append(this[counter]) + counter++ } - builder.append(c) } return builder.toString() -- cgit