Class Parser

java.lang.Object
com.github.tommyettinger.textra.Parser

public class Parser
extends java.lang.Object
Utility class to parse tokens from a TypingLabel; not intended for external use in most situations.
  • Constructor Summary

    Constructors
    Constructor Description
    Parser()  
  • Method Summary

    Modifier and Type Method Description
    static void parseTokens​(TypingLabel label)
    Parses all tokens from the given TypingLabel.
    static java.lang.String preprocess​(java.lang.CharSequence text)
    Replaces any style tags using square brackets, such as [_] for underline, with the syntax {STYLE=_} (changing _ based on what was in the square brackets).
    static boolean stringToBoolean​(java.lang.String str)
    Returns a boolean value parsed from the given String, or the default value if the string couldn't be parsed.
    static int stringToColor​(TypingLabel label, java.lang.String str)
    Parses a color from the given string.
    static java.lang.String stringToColorMarkup​(java.lang.String str)
    Encloses the given string in brackets to work as a regular color markup tag.
    static float stringToFloat​(java.lang.String str, float defaultValue)
    Returns a float value parsed from the given String, or the default value if the string couldn't be parsed.
    static java.lang.String stringToStyleMarkup​(java.lang.String str)
    Matches style names to syntax and encloses the given string in brackets to work as a style markup tag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Parser

      public Parser()
  • Method Details

    • preprocess

      public static java.lang.String preprocess​(java.lang.CharSequence text)
      Replaces any style tags using square brackets, such as [_] for underline, with the syntax {STYLE=_} (changing _ based on what was in the square brackets). This also changes [] to {RESET}. This won't change escaped brackets or the inline image syntax that uses [+name of an image in an atlas].
      Parameters:
      text - text that could have square-bracket style markup
      Returns:
      text with square bracket style markup changed to curly-brace style markup
    • parseTokens

      public static void parseTokens​(TypingLabel label)
      Parses all tokens from the given TypingLabel.
    • stringToFloat

      public static float stringToFloat​(java.lang.String str, float defaultValue)
      Returns a float value parsed from the given String, or the default value if the string couldn't be parsed. This can be useful in Effects.
    • stringToBoolean

      public static boolean stringToBoolean​(java.lang.String str)
      Returns a boolean value parsed from the given String, or the default value if the string couldn't be parsed. This can be useful in Effects.
    • stringToColor

      public static int stringToColor​(TypingLabel label, java.lang.String str)
      Parses a color from the given string. Returns null if the color couldn't be parsed. This can be useful in Effects.
    • stringToColorMarkup

      public static java.lang.String stringToColorMarkup​(java.lang.String str)
      Encloses the given string in brackets to work as a regular color markup tag.
    • stringToStyleMarkup

      public static java.lang.String stringToStyleMarkup​(java.lang.String str)
      Matches style names to syntax and encloses the given string in brackets to work as a style markup tag.