forked from StarOpenSource/Engine
Fix some stuff in ShortcodeParserSkeleton
This commit removes the <negative> tag, remove it from your sources.
This commit is contained in:
parent
0c77f50609
commit
31b1a2d199
1 changed files with 43 additions and 28 deletions
|
@ -24,11 +24,10 @@ import de.staropensource.sosengine.base.logging.LoggerInstance;
|
|||
import de.staropensource.sosengine.base.types.CodePart;
|
||||
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
||||
import lombok.Getter;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* The base skeleton for implementing a shortcode parser.
|
||||
|
@ -71,7 +70,7 @@ public abstract class ShortcodeParserSkeleton {
|
|||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
protected final List<String> components;
|
||||
protected final LinkedList<String> components;
|
||||
|
||||
/**
|
||||
* Constructs this class.
|
||||
|
@ -92,8 +91,8 @@ public abstract class ShortcodeParserSkeleton {
|
|||
* @since v1-alpha1
|
||||
*/
|
||||
@NotNull
|
||||
private List<@NotNull String> parse(@NotNull String string) {
|
||||
List<String> components = new ArrayList<>(); // List of components
|
||||
protected LinkedList<@NotNull String> parse(@NotNull String string) {
|
||||
LinkedList<String> components = new LinkedList<>(); // List of components
|
||||
boolean tagActive = false; // Indicates that a tag is being parsed
|
||||
String part = ""; // Current part. May be a tag, may be regular text
|
||||
|
||||
|
@ -109,26 +108,36 @@ public abstract class ShortcodeParserSkeleton {
|
|||
if (part.startsWith("fg:")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
try {
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=fg data=" + part.substring(3).toUpperCase() + " enum=" + Ansi.Color.valueOf(part.substring(3).toUpperCase()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=fg data=" + part.substring(3).toUpperCase() + " enum=<invalid>");
|
||||
}
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=fg data=" + part.substring(3).toUpperCase());
|
||||
|
||||
components.add("COLOR:FOREGROUND:" + part.substring(3).toUpperCase());
|
||||
if (isValidColor(part.substring(3).toUpperCase()))
|
||||
components.add("COLOR:FOREGROUND:" + part.substring(3).toUpperCase());
|
||||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance().isErrorShortcodeConverter())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
}
|
||||
}
|
||||
|
||||
// bg:*
|
||||
else if (part.startsWith("bg:")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
try {
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bg data=" + part.substring(3).toUpperCase() + " enum=" + Ansi.Color.valueOf(part.substring(3).toUpperCase()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bg data=" + part.substring(3).toUpperCase() + " enum=<invalid>");
|
||||
}
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=bg data=" + part.substring(3).toUpperCase());
|
||||
|
||||
components.add("COLOR:BACKGROUND:" + part.substring(3).toUpperCase());
|
||||
if (isValidColor(part.substring(3).toUpperCase()))
|
||||
components.add("COLOR:BACKGROUND:" + part.substring(3).toUpperCase());
|
||||
else {
|
||||
// Complain about invalid shortcode
|
||||
if (EngineConfiguration.getInstance().isErrorShortcodeConverter())
|
||||
logger.sarn("Invalid shortcode: " + part);
|
||||
|
||||
// Convert tag regular text
|
||||
components.add("TEXT:" + "<" + part + ">");
|
||||
}
|
||||
}
|
||||
|
||||
// bold
|
||||
|
@ -181,16 +190,6 @@ public abstract class ShortcodeParserSkeleton {
|
|||
components.add("ATTRIBUTE:BLINK");
|
||||
}
|
||||
|
||||
// underline
|
||||
else if (part.equals("negative")) {
|
||||
// Print debug message
|
||||
if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
|
||||
System.out.println(getClass().getName() + "#" + string.hashCode() + " tag=negative");
|
||||
|
||||
// Insert attribute
|
||||
components.add("ATTRIBUTE:NEGATIVE");
|
||||
}
|
||||
|
||||
// reset
|
||||
else if (part.equals("reset")) {
|
||||
// Print debug message
|
||||
|
@ -251,4 +250,20 @@ public abstract class ShortcodeParserSkeleton {
|
|||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the supplied color tag and returns if it's valid.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
private boolean isValidColor(@NotNull String color) {
|
||||
switch (color.toLowerCase(Locale.ROOT)) {
|
||||
case "black", "white", "red", "green", "blue", "yellow", "magenta", "cyan" -> {
|
||||
return true;
|
||||
}
|
||||
default -> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue