Top Description Fields Constructors Methods
io.github.kusoroadeolu.clique.parser

public final Record MarkupParser

extends Record
Class Inheritance
Annotations
@Stable
since:3.2.0
@SuppressWarnings:java:S106
Record Components
parserConfiguration:ParserConfiguration 
Imports
io.github.kusoroadeolu.clique.configuration.ParserConfiguration, io.github.kusoroadeolu.clique.internal.documentation.Stable, io.github.kusoroadeolu.clique.internal.markup.ParseResult, .ParseToken, .StyleResolver, .Tokenizer, java.util.List, .Objects

This class parses markup-tagged strings into ANSI-styled output.

Parser rules:

Formerly known as AnsiStringParser prior to version 4.0.0.
Since
1.0.0

Field Summary

Modifier and TypeField and Description
public static final MarkupParser
private final ParserConfiguration
parserConfiguration

Record Component accessed by parserConfiguration().

Constructor Summary

AccessConstructor and Description
public
public
MarkupParser(ParserConfiguration parserConfiguration)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public String

Returns:

the plain text content with all markup and ANSI sequences removed, or the original value if null or blank
getOriginalString
(String
a string that may contain markup tags or ANSI sequences; may be null
tokenedString
)

Strips markup tags and residual ANSI sequences from a previously tokenized string, returning the plain text content.

pack-priv ParseResult
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String

Returns:

the styled string, or the original value if null or blank
parse
(String
the input string, may contain markup tags; may be null
string
)

Parses a markup-tagged string and returns the ANSI-styled result.

public String

Returns:

the styled string
parse
(Object
the object to parse; must not be null
object
)

Parses the Object#toString() representation of object.

public ParserConfiguration
parserConfiguration()

Record Component getter of parserConfiguration.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

DEFAULTback to summary
public static final MarkupParser DEFAULT

A parser using ParserConfiguration#DEFAULT.

parserConfigurationback to summary
private final ParserConfiguration parserConfiguration

Record Component accessed by parserConfiguration().

Constructor Detail

MarkupParserback to summary
public MarkupParser()
MarkupParserback to summary
public MarkupParser(ParserConfiguration parserConfiguration)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
getOriginalStringback to summary
public String getOriginalString(String tokenedString)

Strips markup tags and residual ANSI sequences from a previously tokenized string, returning the plain text content.

If tokenedString is null or blank, it is returned as-is.

Example:

parser.getOriginalString("[bold]Hello[/]"); // returns "Hello"
Parameters
tokenedString:String

a string that may contain markup tags or ANSI sequences; may be null

Returns:String

the plain text content with all markup and ANSI sequences removed, or the original value if null or blank

getParseResultback to summary
pack-priv ParseResult getParseResult(String input)
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

parseback to summary
public String parse(String string)

Parses a markup-tagged string and returns the ANSI-styled result.

Parameters
string:String

the input string, may contain markup tags; may be null

Returns:String

the styled string, or the original value if null or blank

parseback to summary
public String parse(Object object)

Parses the Object#toString() representation of object.

Parameters
object:Object

the object to parse; must not be null

Returns:String

the styled string

Exceptions
NullPointerException:
if object is null
parserConfigurationback to summary
public ParserConfiguration parserConfiguration()

Record Component getter of parserConfiguration.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.