From e5f7b0e580494d6def2d1225f51e0e2e11a37bfe Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Thu, 25 Jul 2024 20:03:46 +0200 Subject: [PATCH] Migrate ShortcodeParserSkeleton to StringBuilder --- .../base/classes/ShortcodeParserSkeleton.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java b/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java index d3335cd2..94adfe65 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java +++ b/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java @@ -100,17 +100,17 @@ public abstract class ShortcodeParserSkeleton { LinkedList 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); } }