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