Parser class final
A parser that processes strings containing ANSI escape codes and tracks the current Style.
Parser allows you to perform various operations on strings with ANSI sequences, such as:
- Stripping out the escape codes using
removeAll. - Optimizing the string to remove redundant codes using
optimize. - Extracting a substring while preserving the active style using
substring. - Inserting text that takes the style of the place it lands in and leaves
the rest of the string as it was using
insertBeforeandinsertAfter. - Retrieving the computed Style at a specific text position using
stateAtandfinalState. - Retrieving the hyperlink in force at a text position using
linkAtandfinalLink. - Analyzing a string using
pieces.
Parser allows you to work with a string containing ANSI escape codes as with a regular string without ANSI escape codes:
length- string length without ANSI escape codes.indexOf- index of the first occurrence of a pattern in the string without ANSI escape codes.lastIndexOf- index of the last occurrence of a pattern in the string without ANSI escape codes.contains- whether the string contains a pattern in the string without ANSI escape codes.startsWith- whether the string starts with a pattern in the string without ANSI escape codes.endsWith- whether the string ends with a pattern in the string without ANSI escape codes.
On a large input, prefer walking pieces with a for and taking what
the loop needs as it goes: the walk parses lazily, and what it has read
it keeps. prepare, length and the string methods read the whole
string and keep every piece, which on megabytes of input is megabytes
of parse tree.
Keeping a Text from that walk after the loop is not free either, and reading its Text.string does not make it so: see Text.string for what a kept piece holds onto for as long as it is kept.
Constructors
Properties
- finalLink → OscLink?
-
The hyperlink the string leaves open, or
nullwhere it leaves none.no setterinherited - finalState → Style
-
The final
Safter processing the entire string.no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- initialLink → OscLink?
-
The link the string is read as starting inside, where there is one.
finalinherited
- initialState → Style
-
The state the string is read as starting in.
finalinherited
- input → String
-
The string being read, escape codes and all.
finalinherited
- isClosed → bool
-
Whether the string ends in the state it began in.
no setterinherited
- isParsed → bool
-
Whether the whole string has been read, rather than as much of it as the
questions asked so far needed. See
prepare.no setterinherited - length → int
-
String length without ANSI escape codes, in UTF-16 code units.
no setterinherited
-
pieces
→ Pieces<
Style> -
The Pieces of the string.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
contains(
Pattern other, [int startIndex = 0]) → bool -
Whether the string contains a pattern in the string without ANSI escape
codes.
inherited
-
endsWith(
String other) → bool -
Whether the string ends with a pattern in the string without ANSI
escape codes.
inherited
-
indexOf(
Pattern pattern) → int -
Index of the first occurrence of a pattern in the string without ANSI
escape codes.
inherited
-
insertAfter(
int pos, String text) → String -
Inserts
textat the plain textpos, behind the escape codes standing there.inherited -
insertBefore(
int pos, String text) → String -
Inserts
textat the plain textpos, in front of the escape codes standing there.inherited -
lastIndexOf(
Pattern pattern) → int -
Index of the last occurrence of a pattern in the string without ANSI
escape codes.
inherited
-
linkAt(
int pos) → OscLink? -
The hyperlink open at the plain text
pos, ornullwhere none is.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
optimize(
{bool close = true}) → String -
Optimizes the string by removing consecutive escape codes.
inherited
-
padLeft(
int width, [String padding = ' ']) → String -
The string with
paddingwritten before it until the text iswidthwide.inherited -
padRight(
int width, [String padding = ' ']) → String -
The string with
paddingwritten after it until the text iswidthwide.inherited -
prepare(
) → void -
Reads the whole string, ahead of the questions asked of it.
inherited
-
removeAll(
) → String -
Returns the string without ANSI escape codes.
inherited
-
replaceAll(
String replace(EscapeCode code), {String replacePlainText(Text entity)?}) → String -
Replaces all EscapeCodes in the string with the result of the
replacefunction.inherited -
showControlFunctions(
{String open = '[', String close = ']'}) → String -
Returns a string in which all EscapeCode are replaced with their
identifiers.
inherited
-
startsWith(
Pattern pattern, [int index = 0]) → bool -
Whether the string starts with a pattern in the string without ANSI
escape codes.
inherited
-
stateAt(
int pos) → Style -
Returns the
Sof the string at the given plain textpos.inherited -
substring(
int start, {int? maxLength, bool close = true}) → String -
Returns a substring of the given
startposition while preserving the text style.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited