Migrate ShortcodeParserSkeleton to StringBuilder

This commit is contained in:
JeremyStar™ 2024-07-25 20:03:46 +02:00
parent b9d4196b8b
commit e5f7b0e580
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -100,17 +100,17 @@ public abstract class ShortcodeParserSkeleton {
LinkedList<String> components = new LinkedList<>(); // List of components
boolean tagActive = false; // Indicates that a tag is being parsed
boolean escape = false; // Indicates whether the last character was a \ character
String part = ""; // Temporary string. May be a tag, may be regular text
StringBuilder part = new StringBuilder(); // Temporary string. May be a tag, may be regular text
// Iterate through every character
for (char character : string.toCharArray()) {
// Escaping
if (escape) {
if (character == '\\' || character == '<')
part += character;
part.append(character);
else if (!(character == 'r' || character == 'n'))
if (ignoreInvalidEscapes)
part += "\\" + character;
part.append("\\").append(character);
else
throw new ParserException("Invalid escape \\" + character);
@ -129,7 +129,7 @@ public abstract class ShortcodeParserSkeleton {
tagActive = false;
// fg:*
if (part.startsWith("fg:")) {
if (part.toString().startsWith("fg:")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=fg data=" + part.substring(3).toUpperCase());
@ -147,7 +147,7 @@ public abstract class ShortcodeParserSkeleton {
}
// bg:*
else if (part.startsWith("bg:")) {
else if (part.toString().startsWith("bg:")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bg data=" + part.substring(3).toUpperCase());
@ -165,7 +165,7 @@ public abstract class ShortcodeParserSkeleton {
}
// bold
else if (part.equals("bold")) {
else if (part.toString().equals("bold")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bold");
@ -175,7 +175,7 @@ public abstract class ShortcodeParserSkeleton {
}
// italic
else if (part.equals("italic")) {
else if (part.toString().equals("italic")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=italic");
@ -185,7 +185,7 @@ public abstract class ShortcodeParserSkeleton {
}
// strikethrough
else if (part.equals("strikethrough")) {
else if (part.toString().equals("strikethrough")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=strikethrough");
@ -195,7 +195,7 @@ public abstract class ShortcodeParserSkeleton {
}
// underline
else if (part.equals("underline")) {
else if (part.toString().equals("underline")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=underline");
@ -205,7 +205,7 @@ public abstract class ShortcodeParserSkeleton {
}
// underline
else if (part.equals("blink")) {
else if (part.toString().equals("blink")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=blink");
@ -215,7 +215,7 @@ public abstract class ShortcodeParserSkeleton {
}
// reset
else if (part.equals("reset")) {
else if (part.toString().equals("reset")) {
// Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=reset");
@ -239,11 +239,11 @@ public abstract class ShortcodeParserSkeleton {
}
// Empty 'part'
part = "";
part = new StringBuilder();
} else
// Tag has not ended yet, add character to 'part'
//noinspection StringConcatenationInLoop // It bloats the code to do it with StringBuilder
part += character;
// It bloats the code to do it with StringBuilder
part.append(character);
} else {
// Regular text is being parsed
if (character == '<') {
@ -253,14 +253,14 @@ public abstract class ShortcodeParserSkeleton {
System.out.println(getClass().getName() + "#" + string.hashCode() + " text=" + part);
components.add("TEXT:" + part);
part = "";
part = new StringBuilder();
}
tagActive = true; // Enable tag processing
} else
// Regular text, add character to 'part'
//noinspection StringConcatenationInLoop // It bloats the code to do it with StringBuilder
part += character;
// It bloats the code to do it with StringBuilder
part.append(character);
}
}