Fix some stuff in ShortcodeParserSkeleton

This commit removes the <negative> tag, remove it from your sources.
This commit is contained in:
JeremyStar™ 2024-07-16 14:47:17 +02:00
parent 0c77f50609
commit 31b1a2d199
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -24,11 +24,10 @@ import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.CodePart; import de.staropensource.sosengine.base.types.CodePart;
import de.staropensource.sosengine.base.types.logging.LogIssuer; import de.staropensource.sosengine.base.types.logging.LogIssuer;
import lombok.Getter; import lombok.Getter;
import org.fusesource.jansi.Ansi;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.LinkedList;
import java.util.List; import java.util.Locale;
/** /**
* The base skeleton for implementing a shortcode parser. * The base skeleton for implementing a shortcode parser.
@ -71,7 +70,7 @@ public abstract class ShortcodeParserSkeleton {
*/ */
@NotNull @NotNull
@Getter @Getter
protected final List<String> components; protected final LinkedList<String> components;
/** /**
* Constructs this class. * Constructs this class.
@ -92,8 +91,8 @@ public abstract class ShortcodeParserSkeleton {
* @since v1-alpha1 * @since v1-alpha1
*/ */
@NotNull @NotNull
private List<@NotNull String> parse(@NotNull String string) { protected LinkedList<@NotNull String> parse(@NotNull String string) {
List<String> components = new ArrayList<>(); // 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
String part = ""; // Current part. May be a tag, may be regular text String part = ""; // Current part. May be a tag, may be regular text
@ -109,26 +108,36 @@ public abstract class ShortcodeParserSkeleton {
if (part.startsWith("fg:")) { if (part.startsWith("fg:")) {
// Print debug message // Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter()) if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
try { 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() + " 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>");
}
if (isValidColor(part.substring(3).toUpperCase()))
components.add("COLOR:FOREGROUND:" + 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:* // bg:*
else if (part.startsWith("bg:")) { else if (part.startsWith("bg:")) {
// Print debug message // Print debug message
if (EngineConfiguration.getInstance().isDebugShortcodeConverter()) if (EngineConfiguration.getInstance().isDebugShortcodeConverter())
try { 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() + " 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>");
}
if (isValidColor(part.substring(3).toUpperCase()))
components.add("COLOR:BACKGROUND:" + 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 // bold
@ -181,16 +190,6 @@ public abstract class ShortcodeParserSkeleton {
components.add("ATTRIBUTE:BLINK"); 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 // reset
else if (part.equals("reset")) { else if (part.equals("reset")) {
// Print debug message // Print debug message
@ -251,4 +250,20 @@ public abstract class ShortcodeParserSkeleton {
return components; 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;
}
}
}
} }