Class SimpleTextParser
java.lang.Object
org.apache.commons.geometry.io.core.internal.SimpleTextParser
Class providing basic text parsing capabilities. The goals of this class are to
(1) provide a simple, flexible API for performing common text parsing operations and
(2) provide a mechanism for creating consistent and informative parsing errors.
This class is not intended as a replacement for grammar-based parsers and/or lexers.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Internal class used to collect strings from the character stream while ensuring that the collected strings do not exceed the maximum configured string length. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CharReadBuffer
Character read buffer used to access the character stream.private int
Current character column on the current line; column numbers start at 1.private static final char
Carriage return character.private String
The current token.private int
The character number that the current token started on.private int
The line number that the current token started on.private static final int
Default value for the max string length property.private static final int
Constant indicating that the end of the input has been reached.private boolean
Flag used to indicate that at least one token has been read from the stream.private static final int
Initial token position number.private static final char
Line feed character.private int
Current line number; line numbers start counting at 1.private int
Maximum length for strings returned by this instance.private static final IntConsumer
Int consumer that does nothing.private static final String
Error message used when a string exceeds the configured maximum length. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleTextParser
(Reader reader) Construct a new instance that reads characters from the given reader.SimpleTextParser
(CharReadBuffer buffer) Construct a new instance that reads characters from the given character buffer. -
Method Summary
Modifier and TypeMethodDescriptionint
Return the index of the argument that exactly matches thecurrent token
.int
Return the index of the argument that exactly matches thecurrent token
.int
chooseIgnoreCase
(String... expected) Return the index of the argument that matches thecurrent token
, ignoring case.int
chooseIgnoreCase
(List<String> expected) Return the index of the argument that matches thecurrent token
, ignoring case.private int
chooseInternal
(List<String> expected, boolean caseSensitive, boolean throwOnFailure) Internal method to compare the current token with a list of possible strings.consume
(int len, IntConsumer consumer) Consume at mostlen
characters from the stream, passing each to the given consumer.consume
(IntPredicate pred, IntConsumer consumer) Consume characters from the stream and pass them toconsumer
while the given predicate returns true.consumeWithLineContinuation
(char lineContinuationChar, int len, IntConsumer consumer) Consume at mostlen
characters from the stream, passing each to the given consumer.consumeWithLineContinuation
(char lineContinuationChar, IntPredicate pred, IntConsumer consumer) Consume characters from the stream and pass them toconsumer
while the given predicate returns true.discard
(int len) Discardlen
number of characters from the character stream.discard
(IntPredicate pred) Discard characters from the stream while the given predicate returns true.Discard all remaining characters on the current line, including the terminating newline character sequence.Discard the next whitespace characters on the current line.Discard the newline character sequence at the current reader position.Discard a sequence of whitespace characters from the character stream starting from the current parser position.discardWithLineContinuation
(char lineContinuationChar, int len) Discardlen
number of characters from the character stream.discardWithLineContinuation
(char lineContinuationChar, IntPredicate pred) Discard characters from the stream while the given predicate returns true.private void
Ensure that a token read operation has been performed, throwing an exception if not.int
Get the current column number.Get the current token.double
Get the current token parsed as a double.int
Get the current token parsed as an integer.int
Get the column position that the current token started on.private String
Get a user-friendly description of the current token.int
Get the line number that the current token started on.int
Get the current line number.int
Get the maximum length for strings returned by this instance.boolean
Return true if there are more characters to read from this instance.boolean
Return true if there are more characters to read on the current line.boolean
Return true if the current token is not null or empty.static boolean
isAlphanumeric
(int ch) Return true if the given character (Unicode code point) is alphanumeric.static boolean
isDecimalPart
(int ch) Return true if the given character (Unicode code point) can be used as part of the string representation of a decimal number.static boolean
isIntegerPart
(int ch) Return true if the given character (Unicode code point) can be used as part of the string representation of an integer.static boolean
isLineWhitespace
(int ch) Return true if the given character (Unicode code point) is whitespace that is not used in newline sequences (ie, not '\r' or '\n').static boolean
isNewLinePart
(int ch) Return true if the given character (Unicode code point) is used as part of newline sequences (ie, is either '\r' or '\n').static boolean
isNotAlphanumeric
(int ch) Return true if the given character (Unicode code point) is not alphanumeric.static boolean
isNotNewLinePart
(int ch) Return true if the given character (Unicode code point) is not used as part of newline sequences (ie, not '\r' or '\n').static boolean
isNotWhitespace
(int ch) Return true if the given character (Unicode code point) is not whitespace.static boolean
isWhitespace
(int ch) Return true if the given character (Unicode code point) is whitespace.Compare thecurrent token
with the argument and throw an exception if they are not equal.matchIgnoreCase
(String expected) Compare thecurrent token
with the argument and throw an exception if they are not equal.private boolean
matchInternal
(String expected, boolean caseSensitive, boolean throwOnFailure) Internal method to compare the current token with the argument.next
(int len) Read a string containing at mostlen
characters from the stream and set it as the current token.next
(IntPredicate pred) Read characters from the stream while the given predicate returns true and set the result as the current token.Read a sequence of alphanumeric characters starting from the current parser position and set the result as the current token.nextLine()
Read characters from the current parser position to the next new line sequence and set the result as the current token .nextWithLineContinuation
(char lineContinuationChar, int len) Read a string containing at mostlen
characters from the stream and set it as the current token.nextWithLineContinuation
(char lineContinuationChar, IntPredicate pred) Read characters from the stream while the given predicate returns true and set the result as the current token.parseError
(int line, int col, String msg) Return an exception indicating an error during parsing.parseError
(int line, int col, String msg, Throwable cause) Return an exception indicating an error during parsing.parseError
(String msg) Return an exception indicating an error occurring at the current parser position.parseError
(String msg, Throwable cause) Return an exception indicating an error occurring at the current parser position.peek
(int len) Return a string containing containing at mostlen
characters from the stream but without changing the parser position.peek
(IntPredicate pred) Read characters from the stream while the given predicate returns true but do not change the current token or advance the parser position.int
peekChar()
Return the next character in the stream but do not advance the parser position.int
readChar()
Read and return the next character in the stream and advance the parser position.void
setColumnNumber
(int column) Set the current column number.void
setLineNumber
(int lineNumber) Set the current line number.void
setMaxStringLength
(int maxStringLength) Set the maximum length for strings returned by this instance.private void
Set the current token string and position.private static boolean
stringsEqual
(String a, String b, boolean caseSensitive) Test two strings for equality.tokenError
(String msg) Get an exception indicating an error during parsing at the current token position.tokenError
(String msg, Throwable cause) Get an exception indicating an error during parsing at the current token position.int
Return the index of the argument that exactly matches thecurrent token
or -1 if no match is found.int
Return the index of the argument that exactly matches thecurrent token
or -1 if no match is found.int
tryChooseIgnoreCase
(String... expected) Return the index of the argument that matches thecurrent token
or -1 if no match is found.int
tryChooseIgnoreCase
(List<String> expected) Return the index of the argument that matches thecurrent token
or -1 if no match is found.boolean
Return true if thecurrent token
is equal to the argument.boolean
tryMatchIgnoreCase
(String expected) Return true if thecurrent token
is equal to the argument.unexpectedToken
(String expected) Get an exception indicating that the current token was unexpected.unexpectedToken
(String expected, Throwable cause) Get an exception indicating that the current token was unexpected.private void
validateRequestedStringLength
(int len) Validate the requested string length.
-
Field Details
-
EOF
private static final int EOFConstant indicating that the end of the input has been reached.- See Also:
-
CR
private static final char CRCarriage return character.- See Also:
-
LF
private static final char LFLine feed character.- See Also:
-
DEFAULT_MAX_STRING_LENGTH
private static final int DEFAULT_MAX_STRING_LENGTHDefault value for the max string length property.- See Also:
-
STRING_LENGTH_ERR_MSG
Error message used when a string exceeds the configured maximum length.- See Also:
-
INITIAL_TOKEN_POS
private static final int INITIAL_TOKEN_POSInitial token position number.- See Also:
-
NOOP_CONSUMER
Int consumer that does nothing. -
lineNumber
private int lineNumberCurrent line number; line numbers start counting at 1. -
columnNumber
private int columnNumberCurrent character column on the current line; column numbers start at 1. -
maxStringLength
private int maxStringLengthMaximum length for strings returned by this instance. -
currentToken
The current token. -
currentTokenLineNumber
private int currentTokenLineNumberThe line number that the current token started on. -
currentTokenColumnNumber
private int currentTokenColumnNumberThe character number that the current token started on. -
hasSetToken
private boolean hasSetTokenFlag used to indicate that at least one token has been read from the stream. -
buffer
Character read buffer used to access the character stream.
-
-
Constructor Details
-
SimpleTextParser
Construct a new instance that reads characters from the given reader. The reader will not be closed.- Parameters:
reader
- reader instance to read characters from
-
SimpleTextParser
Construct a new instance that reads characters from the given character buffer.- Parameters:
buffer
- read buffer to read characters from
-
-
Method Details
-
getLineNumber
public int getLineNumber()Get the current line number. Line numbers start at 1.- Returns:
- the current line number
-
setLineNumber
public void setLineNumber(int lineNumber) Set the current line number. This does not affect the character stream position, only the value returned bygetLineNumber()
.- Parameters:
lineNumber
- line number to set; line numbers start at 1
-
getColumnNumber
public int getColumnNumber()Get the current column number. This indicates the column position of the character that will returned by the next call toreadChar()
. The first character of each line has a column number of 1.- Returns:
- the current column number; column numbers start at 1
-
setColumnNumber
public void setColumnNumber(int column) Set the current column number. This does not affect the character stream position, only the value returned bygetColumnNumber()
.- Parameters:
column
- the column number to set; column numbers start at 1
-
getMaxStringLength
public int getMaxStringLength()Get the maximum length for strings returned by this instance. Operations that produce strings longer than this length will throw an exception.- Returns:
- maximum length for strings returned by this instance
-
setMaxStringLength
public void setMaxStringLength(int maxStringLength) Set the maximum length for strings returned by this instance. Operations that produce strings longer than this length will throw an exception.- Parameters:
maxStringLength
- maximum length for strings returned by this instance- Throws:
IllegalArgumentException
- if the argument is less than zero
-
getCurrentToken
Get the current token. This is the most recent string read by one of thenextXXX()
methods. This value will be null if no token has yet been read or if the end of content has been reached.- Returns:
- the current token
- See Also:
-
hasNonEmptyToken
public boolean hasNonEmptyToken()Return true if the current token is not null or empty.- Returns:
- true if the current token is not null or empty
- See Also:
-
getCurrentTokenLineNumber
public int getCurrentTokenLineNumber()Get the line number that the current token started on. This value will be -1 if no token has been read yet.- Returns:
- current token starting line number or -1 if no token has been read yet
- See Also:
-
getCurrentTokenColumnNumber
public int getCurrentTokenColumnNumber()Get the column position that the current token started on. This value will be -1 if no token has been read yet.- Returns:
- current token column number or -1 if no oken has been read yet
- See Also:
-
getCurrentTokenAsInt
public int getCurrentTokenAsInt()Get the current token parsed as an integer.- Returns:
- the current token parsed as an integer
- Throws:
IllegalStateException
- if no token has been read or the current token cannot be parsed as an integer
-
getCurrentTokenAsDouble
public double getCurrentTokenAsDouble()Get the current token parsed as a double.- Returns:
- the current token parsed as a double
- Throws:
IllegalStateException
- if no token has been read or the current token cannot be parsed as a double
-
hasMoreCharacters
public boolean hasMoreCharacters()Return true if there are more characters to read from this instance.- Returns:
- true if there are more characters to read from this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
hasMoreCharactersOnLine
public boolean hasMoreCharactersOnLine()Return true if there are more characters to read on the current line.- Returns:
- true if there are more characters to read on the current line
- Throws:
UncheckedIOException
- if an I/O error occurs
-
readChar
public int readChar()Read and return the next character in the stream and advance the parser position. This method updates the current line number and column number but does not set thecurrent token
.- Returns:
- the next character in the stream or -1 if the end of the stream has been reached
- Throws:
UncheckedIOException
- if an I/O error occurs- See Also:
-
next
Read a string containing at mostlen
characters from the stream and set it as the current token. Characters are added to the string until the string has the specified length or the end of the stream is reached. The characters are consumed from the stream. The token is set to null if no more characters are available from the character stream when this method is called.- Parameters:
len
- the maximum length of the extracted string- Returns:
- this instance
- Throws:
IllegalArgumentException
- iflen
is less than 0 or greater than the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
nextWithLineContinuation
Read a string containing at mostlen
characters from the stream and set it as the current token. This is similar tonext(int)
but with the exception that new line sequences beginning withlineContinuationChar
are skipped.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequenceslen
- the maximum length of the extracted string- Returns:
- this instance
- Throws:
IllegalArgumentException
- iflen
is less than 0 or greater than the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
next
Read characters from the stream while the given predicate returns true and set the result as the current token. The next call toreadChar()
will return either a character that fails the predicate test or -1 if the end of the stream has been reached. The token will be null if the end of the stream has been reached prior to the method call.- Parameters:
pred
- predicate function passed characters read from the input; reading continues until the predicate returns false- Returns:
- this instance
- Throws:
IllegalStateException
- if the length of the produced string exceeds the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
nextWithLineContinuation
Read characters from the stream while the given predicate returns true and set the result as the current token. This is similar tonext(IntPredicate)
but with the exception that new line sequences prefixed withlineContinuationChar
are skipped.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequencespred
- predicate function passed characters read from the input; reading continues until the predicate returns false- Returns:
- this instance
- Throws:
IllegalStateException
- if the length of the produced string exceeds the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
nextLine
Read characters from the current parser position to the next new line sequence and set the result as the current token . The newline character sequence ('\r', '\n', or '\r\n') at the end of the line is consumed but is not included in the token. The token will be null if the end of the stream has been reached prior to the method call.- Returns:
- this instance
- Throws:
IllegalStateException
- if the length of the produced string exceeds the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
nextAlphanumeric
Read a sequence of alphanumeric characters starting from the current parser position and set the result as the current token. The token will be the empty string if the next character in the stream is not alphanumeric and will be null if the end of the stream has been reached prior to the method call.- Returns:
- this instance
- Throws:
IllegalStateException
- if the length of the produced string exceeds the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
discard
Discardlen
number of characters from the character stream. The parser position is updated but the current token is not changed.- Parameters:
len
- number of characters to discard- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardWithLineContinuation
Discardlen
number of characters from the character stream. The parser position is updated but the current token is not changed. Lines beginning withlineContinuationChar
are skipped.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequenceslen
- number of characters to discard- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discard
Discard characters from the stream while the given predicate returns true. The next call toreadChar()
will return either a character that fails the predicate test or -1 if the end of the stream has been reached. The parser position is updated but the current token is not changed.- Parameters:
pred
- predicate test for characters to discard- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardWithLineContinuation
Discard characters from the stream while the given predicate returns true. New line sequences beginning withlineContinuationChar
are skipped. The next call oreadChar()
will return either a character that fails the predicate test or -1 if the end of the stream has been reached. The parser position is updated but the current token is not changed.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequencespred
- predicate test for characters to discard- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardWhitespace
Discard a sequence of whitespace characters from the character stream starting from the current parser position. The next call toreadChar()
will return either a non-whitespace character or -1 if the end of the stream has been reached. The parser position is updated but the current token is not changed.- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardLineWhitespace
Discard the next whitespace characters on the current line. The next call toreadChar()
will return either a non-whitespace character on the current line, the newline character sequence (indicating the end of the line), or -1 (indicating the end of the stream). The parser position is updated but the current token is not changed.- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardNewLineSequence
Discard the newline character sequence at the current reader position. The sequence is defined as one of "\r", "\n", or "\r\n". Does nothing if the reader is not positioned at a newline sequence. The parser position is updated but the current token is not changed.- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
discardLine
Discard all remaining characters on the current line, including the terminating newline character sequence. The next call toreadChar()
will return either the first character on the next line or -1 if the end of the stream has been reached. The parser position is updated but the current token is not changed.- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
consume
Consume characters from the stream and pass them toconsumer
while the given predicate returns true. The operation ends when the predicate returns false or the end of the stream is reached.- Parameters:
pred
- predicate test for characters to consumeconsumer
- object to be passed each consumed character- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
consumeWithLineContinuation
public SimpleTextParser consumeWithLineContinuation(char lineContinuationChar, int len, IntConsumer consumer) Consume at mostlen
characters from the stream, passing each to the given consumer. This method is similar toconsume(int, IntConsumer)
with the exception that new line sequences prefixed withlineContinuationChar
are skipped.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequenceslen
- number of characters to consumeconsumer
- function to be passed each consumed character- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
consume
Consume at mostlen
characters from the stream, passing each to the given consumer. The operation continues untillen
number of characters have been read or the end of the stream has been reached.- Parameters:
len
- number of characters to consumeconsumer
- object to be passed each consumed character- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
consumeWithLineContinuation
public SimpleTextParser consumeWithLineContinuation(char lineContinuationChar, IntPredicate pred, IntConsumer consumer) Consume characters from the stream and pass them toconsumer
while the given predicate returns true. This method is similar toconsume(IntPredicate, IntConsumer)
with the exception that new lines sequences beginning withlineContinuationChar
are skipped.- Parameters:
lineContinuationChar
- character used to indicate skipped new line sequencespred
- predicate test for characters to consumeconsumer
- object to be passed each consumed character- Returns:
- this instance
- Throws:
UncheckedIOException
- if an I/O error occurs
-
peekChar
public int peekChar()Return the next character in the stream but do not advance the parser position.- Returns:
- the next character in the stream or -1 if the end of the stream has been reached
- Throws:
UncheckedIOException
- if an I/O error occurs- See Also:
-
peek
Return a string containing containing at mostlen
characters from the stream but without changing the parser position. Characters are added to the string until the string has the specified length or the end of the stream is reached.- Parameters:
len
- the maximum length of the returned string- Returns:
- a string containing containing at most
len
characters from the stream or null if the parser has already reached the end of the stream - Throws:
IllegalArgumentException
- iflen
is less than 0 or greater than the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
peek
Read characters from the stream while the given predicate returns true but do not change the current token or advance the parser position.- Parameters:
pred
- predicate function passed characters read from the input; reading continues until the predicate returns false- Returns:
- string containing characters matching
pred
or null if the parser has already reached the end of the stream - Throws:
IllegalStateException
- if the length of the produced string exceeds the configuredmaximum string length
UncheckedIOException
- if an I/O error occurs- See Also:
-
match
Compare thecurrent token
with the argument and throw an exception if they are not equal. The comparison is case-sensitive.- Parameters:
expected
- expected token- Returns:
- this instance
- Throws:
IllegalStateException
- if no token has been read orexpected
does not exactly equal the current token
-
matchIgnoreCase
Compare thecurrent token
with the argument and throw an exception if they are not equal. The comparison is not case-sensitive.- Parameters:
expected
- expected token- Returns:
- this instance
- Throws:
IllegalStateException
- if no token has been read orexpected
does not equal the current token (ignoring case)
-
tryMatch
Return true if thecurrent token
is equal to the argument. The comparison is case-sensitive.- Parameters:
expected
- expected token- Returns:
- true if the argument exactly equals the current token
- Throws:
IllegalStateException
- if no token has been readUncheckedIOException
- if an I/O error occurs
-
tryMatchIgnoreCase
Return true if thecurrent token
is equal to the argument. The comparison is not case-sensitive.- Parameters:
expected
- expected token- Returns:
- true if the argument equals the current token (ignoring case)
- Throws:
IllegalStateException
- if no token has been read
-
matchInternal
Internal method to compare the current token with the argument.- Parameters:
expected
- expected tokencaseSensitive
- if the comparison should be case-sensitivethrowOnFailure
- if an exception should be thrown if the argument is not equal to the current token- Returns:
- true if the argument is equal to the current token
- Throws:
IllegalStateException
- if no token has been read orexpected
does not match the current token andthrowOnFailure
is true
-
choose
Return the index of the argument that exactly matches thecurrent token
. An exception is thrown if no match is found. String comparisons are case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that exactly matches the current token
- Throws:
IllegalStateException
- if no token has been read or no match is found among the arguments
-
choose
Return the index of the argument that exactly matches thecurrent token
. An exception is thrown if no match is found. String comparisons are case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that exactly matches the current token
- Throws:
IllegalStateException
- if no token has been read or no match is found among the arguments
-
chooseIgnoreCase
Return the index of the argument that matches thecurrent token
, ignoring case. An exception is thrown if no match is found. String comparisons are not case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that matches the current token (ignoring case)
- Throws:
IllegalStateException
- if no token has been read or no match is found among the arguments
-
chooseIgnoreCase
Return the index of the argument that matches thecurrent token
, ignoring case. An exception is thrown if no match is found. String comparisons are not case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that matches the current token (ignoring case)
- Throws:
IllegalStateException
- if no token has been read or no match is found among the arguments
-
tryChoose
Return the index of the argument that exactly matches thecurrent token
or -1 if no match is found. String comparisons are case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that exactly matches the current token or -1 if no match is found
- Throws:
IllegalStateException
- if no token has been read
-
tryChoose
Return the index of the argument that exactly matches thecurrent token
or -1 if no match is found. String comparisons are case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that exactly matches the current token or -1 if no match is found
- Throws:
IllegalStateException
- if no token has been read
-
tryChooseIgnoreCase
Return the index of the argument that matches thecurrent token
or -1 if no match is found. String comparisons are not case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that matches the current token (ignoring case) or -1 if no match is found
- Throws:
IllegalStateException
- if no token has been read
-
tryChooseIgnoreCase
Return the index of the argument that matches thecurrent token
or -1 if no match is found. String comparisons are not case-sensitive.- Parameters:
expected
- strings to compare with the current token- Returns:
- index of the argument that matches the current token (ignoring case) or -1 if no match is found
- Throws:
IllegalStateException
- if no token has been read
-
chooseInternal
Internal method to compare the current token with a list of possible strings. The index of the matching argument is returned.- Parameters:
expected
- strings to compare with the current tokencaseSensitive
- if the comparisons should be case-sensitivethrowOnFailure
- if an exception should be thrown if no match is found- Returns:
- the index of the matching argument or -1 if no match is found
- Throws:
IllegalStateException
- if no token has been read or no match is found andthrowOnFailure
is true
-
unexpectedToken
Get an exception indicating that the current token was unexpected. The returned exception contains a message with the line number and column of the current token and a description of its value.- Parameters:
expected
- string describing what was expected- Returns:
- exception indicating that the current token was unexpected
-
unexpectedToken
Get an exception indicating that the current token was unexpected. The returned exception contains a message with the line number and column of the current token and a description of its value.- Parameters:
expected
- string describing what was expectedcause
- cause of the error- Returns:
- exception indicating that the current token was unexpected
-
tokenError
Get an exception indicating an error during parsing at the current token position.- Parameters:
msg
- error message- Returns:
- an exception indicating an error during parsing at the current token position
-
tokenError
Get an exception indicating an error during parsing at the current token position.- Parameters:
msg
- error messagecause
- the cause of the error; may be null- Returns:
- an exception indicating an error during parsing at the current token position
-
parseError
Return an exception indicating an error occurring at the current parser position.- Parameters:
msg
- error message- Returns:
- an exception indicating an error during parsing
-
parseError
Return an exception indicating an error occurring at the current parser position.- Parameters:
msg
- error messagecause
- the cause of the error; may be null- Returns:
- an exception indicating an error during parsing
-
parseError
Return an exception indicating an error during parsing.- Parameters:
line
- line number of the errorcol
- column number of the errormsg
- error message- Returns:
- an exception indicating an error during parsing
-
parseError
Return an exception indicating an error during parsing.- Parameters:
line
- line number of the errorcol
- column number of the errormsg
- error messagecause
- the cause of the error- Returns:
- an exception indicating an error during parsing
-
setToken
Set the current token string and position.- Parameters:
line
- line number for the start of the tokencol
- column number for the start of the tokentoken
- token to set
-
getCurrentTokenDescription
Get a user-friendly description of the current token.- Returns:
- a user-friendly description of the current token.
-
validateRequestedStringLength
private void validateRequestedStringLength(int len) Validate the requested string length.- Parameters:
len
- requested string length- Throws:
IllegalArgumentException
- iflen
is less than 0 or greater thanmaxStringLength
-
ensureHasSetToken
private void ensureHasSetToken()Ensure that a token read operation has been performed, throwing an exception if not.- Throws:
IllegalStateException
- if no token read operation has been performed
-
isWhitespace
public static boolean isWhitespace(int ch) Return true if the given character (Unicode code point) is whitespace.- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character is whitespace
- See Also:
-
isNotWhitespace
public static boolean isNotWhitespace(int ch) Return true if the given character (Unicode code point) is not whitespace.- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character is not whitespace
- See Also:
-
isLineWhitespace
public static boolean isLineWhitespace(int ch) Return true if the given character (Unicode code point) is whitespace that is not used in newline sequences (ie, not '\r' or '\n').- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character is a whitespace character not used in newline sequences
-
isNewLinePart
public static boolean isNewLinePart(int ch) Return true if the given character (Unicode code point) is used as part of newline sequences (ie, is either '\r' or '\n').- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character is used as part of newline sequences
-
isNotNewLinePart
public static boolean isNotNewLinePart(int ch) Return true if the given character (Unicode code point) is not used as part of newline sequences (ie, not '\r' or '\n').- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character is not used as part of newline sequences
- See Also:
-
isAlphanumeric
public static boolean isAlphanumeric(int ch) Return true if the given character (Unicode code point) is alphanumeric.- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the argument is alphanumeric
- See Also:
-
isNotAlphanumeric
public static boolean isNotAlphanumeric(int ch) Return true if the given character (Unicode code point) is not alphanumeric.- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the argument is not alphanumeric
- See Also:
-
isIntegerPart
public static boolean isIntegerPart(int ch) Return true if the given character (Unicode code point) can be used as part of the string representation of an integer. This will be true for the following types of characters:digits
- the '-' (minus) character
- the '+' (plus) character
- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character can be used as part of an integer string
-
isDecimalPart
public static boolean isDecimalPart(int ch) Return true if the given character (Unicode code point) can be used as part of the string representation of a decimal number. This will be true for the following types of characters:digits
- the '-' (minus) character
- the '+' (plus) character
- the '.' (period) character
- the 'e' character
- the 'E' character
- Parameters:
ch
- character (Unicode code point) to test- Returns:
- true if the given character can be used as part of a decimal number string
-
stringsEqual
Test two strings for equality. One or both arguments may be null.- Parameters:
a
- first stringb
- second stringcaseSensitive
- comparison is case-sensitive if set to true- Returns:
- true if the string arguments are considered equal
-