public class Parser
extends java.lang.Object
Buffer
instance.Modifier and Type | Field and Description |
---|---|
private boolean |
bold
Whether bold face is enabled.
|
private java.awt.Color |
color
The color to use.
|
private static java.util.Map<java.lang.String,java.awt.Color> |
COLORS
Maps color tag name to color instance.
|
private static java.util.regex.Pattern |
END_OF_LINE_PATTERN
Pattern to match line breaks.
|
private FontID |
font
The font to use.
|
private static java.util.Map<java.lang.String,FontID> |
FONTS
Maps font tag name to font instance.
|
private boolean |
italic
Whether italic face is enabled.
|
private boolean |
underline
Whether underlining is enabled.
|
private static java.util.regex.Pattern |
WORD_SEPARATOR_PATTERN
The pattern to split a string into words.
|
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
void |
parse(java.lang.CharSequence text,
java.awt.Color defaultColor,
Buffer buffer)
Parses a text message.
|
private Line |
parseLine(java.lang.String text,
java.awt.Color defaultColor)
Parses one text line.
|
private void |
parseLine(java.lang.String text,
java.awt.Color defaultColor,
Buffer buffer)
Parses one text line.
|
private void |
parseLineWithoutMediaTags(java.lang.String text,
Buffer buffer)
Parses one text line of a plain text message without media tags.
|
void |
parseWithoutMediaTags(java.lang.CharSequence text,
java.awt.Color color,
Buffer buffer)
Parses a plain text message without media tags.
|
private void |
processTag(java.lang.String tag,
java.awt.Color defaultColor)
Processes a tag.
|
private void |
processText(java.lang.String text,
Line line)
Processes one text segment.
|
private void |
resetAttributes(java.awt.Color defaultColor)
Resets all attributes to default values.
|
static java.lang.String |
toString(java.awt.Color color)
Returns the string representation for a color.
|
private boolean bold
@Nullable private java.awt.Color color
null
means default color.@NotNull private static final java.util.Map<java.lang.String,java.awt.Color> COLORS
@NotNull private static final java.util.regex.Pattern END_OF_LINE_PATTERN
private FontID font
@NotNull private static final java.util.Map<java.lang.String,FontID> FONTS
private boolean italic
private boolean underline
@NotNull private static final java.util.regex.Pattern WORD_SEPARATOR_PATTERN
public void parse(@NotNull java.lang.CharSequence text, @Nullable java.awt.Color defaultColor, @NotNull Buffer buffer)
text
- the text message to parsedefaultColor
- the default color to usebuffer
- the buffer to update@NotNull private Line parseLine(@NotNull java.lang.String text, @Nullable java.awt.Color defaultColor)
text
- the text to processdefaultColor
- the default color to useLine
instanceprivate void parseLine(@NotNull java.lang.String text, @Nullable java.awt.Color defaultColor, @NotNull Buffer buffer)
text
- the text to processdefaultColor
- the default color to usebuffer
- the buffer instance to add toprivate void parseLineWithoutMediaTags(@NotNull java.lang.String text, @NotNull Buffer buffer)
text
- the text to processbuffer
- the buffer instance to add topublic void parseWithoutMediaTags(@NotNull java.lang.CharSequence text, @NotNull java.awt.Color color, @NotNull Buffer buffer)
text
- the text message to parsecolor
- the color to usebuffer
- the buffer to updateprivate void processTag(@NotNull java.lang.String tag, @Nullable java.awt.Color defaultColor)
tag
- the tag name to process; leading and trailing brackets have
been removeddefaultColor
- the default color to useprivate void processText(@NotNull java.lang.String text, @NotNull Line line)
text
- the text segment to processline
- the line to add toprivate void resetAttributes(@Nullable java.awt.Color defaultColor)
defaultColor
- the default color to use@NotNull public static java.lang.String toString(@NotNull java.awt.Color color)
color
- the color to convert