Skip to content

Commit 156102e

Browse files
committed
Improve colorizeRGB method
1 parent 75e014b commit 156102e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cz.foresttech</groupId>
88
<artifactId>ForestColorAPI</artifactId>
9-
<version>1.5</version>
9+
<version>1.5.1</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>

src/main/java/cz/foresttech/api/ColorAPI.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,23 @@ public static String colorizeGradient(String input) {
156156
* @return colored rgb output
157157
*/
158158
public static String colorizeRGB(String input) {
159-
matcher = patternNormal.matcher(input);
159+
Matcher matcher = patternNormal.matcher(input);
160+
StringBuilder result = new StringBuilder(input.length());
160161

162+
int lastEnd = 0;
161163
while (matcher.find()) {
162164
String color = matcher.group(1);
165+
result.append(input, lastEnd, matcher.start());
166+
163167
if (color != null) {
164-
input = input.replace(matcher.group(), getColor(color) + "");
168+
result.append(getColor(color));
165169
}
170+
171+
lastEnd = matcher.end();
166172
}
167173

168-
return input;
174+
result.append(input.substring(lastEnd));
175+
return result.toString();
169176
}
170177

171178
/**

0 commit comments

Comments
 (0)