public abstract class AbstractStringTokenizer
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static char |
BACKTICK |
static char |
DOUBLE_QUOTE |
static java.util.function.Predicate<java.lang.Character> |
DOUBLE_QUOTE_PRED |
static char |
ESCAPE |
static java.util.function.Predicate<java.lang.Character> |
ESCAPE_PRED |
static java.util.function.Predicate<java.lang.Character> |
QUOTE_PRED |
static char |
SINGLE_QUOTE |
static java.util.function.Predicate<java.lang.Character> |
SINGLE_QUOTE_PRED |
static java.util.function.Predicate<java.lang.Character> |
WHITESPACE_PRED |
| Constructor and Description |
|---|
AbstractStringTokenizer(java.lang.String string) |
| Modifier and Type | Method and Description |
|---|---|
@NotNull java.lang.String |
consumed()
Returns the consumed characters as a string.
|
int |
cursorPosition()
Returns the current cursor position.
|
void |
dropSavedCursor()
Drops the saved cursor position.
|
void |
expect(char expected)
Expects the current character to be the given character.
|
void |
expect(@NotNull java.util.function.Predicate<java.lang.Character> predicate)
Expects the current character to pass the given test.
|
void |
expectWhitespace()
Expects the current character to be whitespace.
|
boolean |
hasNext()
Returns whether the tokenizer has remaining characters.
|
boolean |
hasNext(int offset)
Returns whether the tokenizer has remaining characters at the given offset.
|
int |
length()
Returns the original length of the string.
|
char |
peek()
Returns the character at the current cursor position without consuming it.
|
boolean |
peek(char c)
Checks if the current character matches the given character.
|
char |
peek(int offset)
Returns the character at the given offset from the current cursor position without consuming it.
|
boolean |
peek(@NotNull java.util.function.Predicate<java.lang.Character> predicate)
Checks if the current character matches the given predicate.
|
boolean |
peekWhitespace()
Checks if the current character is a whitespace character.
|
@NotNull java.lang.String |
remaining()
Returns the remaining characters as a string.
|
boolean |
remainingContainsWhitespace()
Checks if the remaining string contains whitespace anywhere.
|
int |
remainingLength()
Returns the number of remaining characters.
|
void |
require(int count)
Ensures that at least the specified number of characters remain.
|
void |
resetCursor()
Resets the cursor position to the beginning.
|
void |
restoreCursor()
Restores the cursor to the last saved position.
|
void |
saveCursor()
Saves the current cursor position.
|
void |
setCursor(int index)
Sets the cursor position to the specified index.
|
void |
setString(@NotNull java.lang.String string)
Sets the string to tokenize.
|
void |
skip()
Skips one character.
|
void |
skip(int offset)
Skips the specified number of characters.
|
void |
skipUntil(char c)
Skips all characters until the given character is found.
|
void |
skipUntil(java.util.function.Predicate<java.lang.Character> predicate)
Skips all characters until the given predicate is matched.
|
void |
skipWhile(char c)
Skips all consecutive occurrences of the given character.
|
void |
skipWhile(java.util.function.Predicate<java.lang.Character> c)
Skips all consecutive characters matching the given predicate.
|
void |
skipWhitespace()
Skips all consecutive whitespace characters.
|
@NotNull java.lang.String |
string()
Returns the string to tokenize.
|
char |
take()
Consumes a single character at the current cursor position.
|
@NotNull java.lang.String |
take(int offset)
Consumes a specified number of characters.
|
@Nullable java.lang.String |
takeQuotedString()
Consumes a quoted (single or double) or unquoted string.
|
@Nullable java.lang.String |
takeQuotedString(boolean lenient)
Consumes a quoted (single or double) or unquoted string.
|
@Nullable java.lang.String |
takeString(@NotNull java.util.function.Predicate<java.lang.Character> predicate)
Consumes a quoted or unquoted string based on the given quote predicate.
|
@Nullable java.lang.String |
takeString(@NotNull java.util.function.Predicate<java.lang.Character> predicate,
boolean allowEmpty,
boolean allowUnterminated)
Consumes a quoted or unquoted string based on the given quote predicate.
|
@NotNull java.lang.String |
takeUnquotedString()
Consumes an unquoted string (until whitespace or end of input).
|
@Nullable java.lang.String |
takeUntil(boolean allowUnterminated,
char terminator)
Consumes all characters until the terminator character is found.
|
@Nullable java.lang.String |
takeUntil(char terminator)
Consumes all characters until the terminator character is found.
|
public static final char ESCAPE
public static final char BACKTICK
public static final char SINGLE_QUOTE
public static final char DOUBLE_QUOTE
public static final java.util.function.Predicate<java.lang.Character> ESCAPE_PRED
public static final java.util.function.Predicate<java.lang.Character> WHITESPACE_PRED
public static final java.util.function.Predicate<java.lang.Character> SINGLE_QUOTE_PRED
public static final java.util.function.Predicate<java.lang.Character> DOUBLE_QUOTE_PRED
public static final java.util.function.Predicate<java.lang.Character> QUOTE_PRED
@NotNull public @NotNull java.lang.String string()
public void setString(@NotNull
@NotNull java.lang.String string)
string - the string to tokenizepublic char take()
throws TokenizerError
TokenizerErrorpublic void expectWhitespace()
throws TokenizerError
TokenizerErrorpublic void expect(char expected)
throws TokenizerError
expected - the expected characterTokenizerErrorpublic void expect(@NotNull
@NotNull java.util.function.Predicate<java.lang.Character> predicate)
throws TokenizerError
predicate - the predicate to test the characterTokenizerErrorpublic boolean hasNext()
public boolean hasNext(int offset)
offset - the offset from the current cursor positionpublic void require(int count)
throws TokenizerError
count - the minimum number of characters requiredTokenizerErrorpublic char peek()
throws TokenizerError
TokenizerErrorpublic char peek(int offset)
throws TokenizerError
offset - the offset from the current cursor position (can be negative)TokenizerErrorpublic boolean peekWhitespace()
throws TokenizerError
TokenizerErrorpublic boolean peek(char c)
throws TokenizerError
c - the character to matchTokenizerErrorpublic boolean peek(@NotNull
@NotNull java.util.function.Predicate<java.lang.Character> predicate)
throws TokenizerError
predicate - the predicate to test the characterTokenizerErrorpublic boolean remainingContainsWhitespace()
public void skip()
throws TokenizerError
TokenizerErrorpublic void skip(int offset)
throws TokenizerError
offset - the amount to skip (can be negative)TokenizerError@NotNull
public @NotNull java.lang.String take(int offset)
throws TokenizerError
offset - the number of characters to consumeTokenizerErrorpublic void resetCursor()
public void setCursor(int index)
index - the new cursor positionpublic void saveCursor()
public void restoreCursor()
public void dropSavedCursor()
@NotNull public @NotNull java.lang.String consumed()
@NotNull public @NotNull java.lang.String remaining()
public int cursorPosition()
public int remainingLength()
public int length()
public void skipWhile(char c)
c - the character to skippublic void skipWhile(java.util.function.Predicate<java.lang.Character> c)
c - the predicate to test the characterspublic void skipUntil(char c)
c - the character to stop atpublic void skipUntil(java.util.function.Predicate<java.lang.Character> predicate)
predicate - the predicate to test the characterspublic void skipWhitespace()
@Nullable public @Nullable java.lang.String takeQuotedString()
@Nullable public @Nullable java.lang.String takeQuotedString(boolean lenient)
lenient - whether to allow unterminated quoted strings@Nullable
public @Nullable java.lang.String takeString(@NotNull
@NotNull java.util.function.Predicate<java.lang.Character> predicate)
predicate - the predicate to test for quote characters@Nullable
public @Nullable java.lang.String takeString(@NotNull
@NotNull java.util.function.Predicate<java.lang.Character> predicate,
boolean allowEmpty,
boolean allowUnterminated)
predicate - the predicate to test for quote charactersallowEmpty - whether to allow empty stringsallowUnterminated - whether to allow unterminated quoted strings@NotNull public @NotNull java.lang.String takeUnquotedString()
@Nullable public @Nullable java.lang.String takeUntil(char terminator)
terminator - the terminator character@Nullable
public @Nullable java.lang.String takeUntil(boolean allowUnterminated,
char terminator)
allowUnterminated - whether to allow unterminated sequencesterminator - the terminator character