Package uk.blankaspect.common.json
Class JsonText
java.lang.Object
uk.blankaspect.common.json.JsonText
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
This class encapsulates a line of text, which consists of a sequence of spans.static final record
This record encapsulates a subsequence of the text of aJsonText.Line
that is associated with a JSON token.static enum
This is an enumeration of the tokens that may be associated with elements of JSON text. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(char ch, JsonText.Token token) Appends the specified character to this JSON text, and adds a new span for the character that associates it with the specified token.void
append
(CharSequence text, JsonText.Token token) Appends the specified text to this JSON text, and adds a new span for the text that associates it with the specified token.If this JSON text is not empty, a line-feed character (U+000A) is appended to it and a new span for it is added to the current line.void
Appends a single space character (U+0020) to this JSON text, and adds a new span for the space.void
appendSpaces
(int numSpaces) Appends the specified number of space characters (U+0020) to this JSON text, and adds a new span for the spaces.buffer()
Returns the buffer that contains the JSON text.lastLine()
Returns the last line of this JSON text within the buffer.int
Returns the length of the last line of this JSON text.lines()
Returns a list of the lines of this JSON text within the buffer.toString()
-
Constructor Details
-
JsonText
public JsonText()Creates a new instance of JSON text.
-
-
Method Details
-
toString
-
buffer
Returns the buffer that contains the JSON text.- Returns:
- the buffer that contains the JSON text.
-
lines
Returns a list of the lines of this JSON text within the buffer.- Returns:
- a list of the lines of this JSON text within the buffer.
-
lastLine
Returns the last line of this JSON text within the buffer.- Returns:
- the last line of this JSON text within the buffer, or
null
if there are no lines.
-
lastLineLength
public int lastLineLength()Returns the length of the last line of this JSON text.- Returns:
- the length of the last line of JSON text, or 0 if there are no lines.
-
append
Appends the specified character to this JSON text, and adds a new span for the character that associates it with the specified token.- Parameters:
ch
- the character that will be appended to this JSON text.token
- the token with whichch
will be associated in the span that is created for it.
-
append
Appends the specified text to this JSON text, and adds a new span for the text that associates it with the specified token.- Parameters:
text
- the text that will be appended to this JSON text.token
- the token with whichtext
will be associated in the span that is created for it.
-
appendSpace
public void appendSpace()Appends a single space character (U+0020) to this JSON text, and adds a new span for the space. -
appendSpaces
public void appendSpaces(int numSpaces) Appends the specified number of space characters (U+0020) to this JSON text, and adds a new span for the spaces.- Parameters:
numSpaces
- the number of space characters that will be appended to this JSON text.
-
appendNewLine
If this JSON text is not empty, a line-feed character (U+000A) is appended to it and a new span for it is added to the current line. A new line is created and added to the list of lines, and the new line is returned.- Returns:
- a new line that was added to the list of lines.
-