aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorbrainage04 <101778999+brainage04@users.noreply.github.com>2023-09-23 20:49:53 +1000
committerGitHub <noreply@github.com>2023-09-23 12:49:53 +0200
commit1701140aa6829c8282fc11a2f8cecb782ac44ed0 (patch)
tree8661cedb35182159af8de69c47b31b2cb37c0cbe /src/main/java
parent9d4369b26973613c1a9b421308b96e3a2b2f7d76 (diff)
downloadskyhanni-1701140aa6829c8282fc11a2f8cecb782ac44ed0.tar.gz
skyhanni-1701140aa6829c8282fc11a2f8cecb782ac44ed0.tar.bz2
skyhanni-1701140aa6829c8282fc11a2f8cecb782ac44ed0.zip
Small performance improvements when working with color codes #489
* more efficient implementation of String.removeColor()
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt19
1 files changed, 8 insertions, 11 deletions
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()