public interface CharStreamScanner
Modifier and Type | Method and Description |
---|---|
boolean |
expect(char expected)
This method checks that the
current character is equal to the given expected character. |
boolean |
expect(String expected,
boolean ignoreCase)
This method skips all
next characters as long as they equal to the according character of the
expected string. |
boolean |
expectStrict(String expected,
boolean ignoreCase)
This method acts as
expect(String, boolean) but if the expected String is NOT completely present, no
character is consumed and the state of the scanner remains unchanged. |
char |
forceNext()
|
char |
forcePeek()
|
int |
getCurrentIndex()
This method gets the current position in the stream to scan.
|
boolean |
hasNext()
This method determines if there is at least one more character available.
|
char |
next()
This method reads the current character and increments the
index stepping to the next
character. |
char |
peek()
This method reads the current character without incrementing the
index . |
String |
read(int count)
This method reads the number of
next characters given by count and returns them as string. |
int |
readDigit()
This method reads the
next character if it is a digit. |
double |
readDouble()
This method reads the double value (decimal number) starting at the
current position by
reading as many matching characters as available and returns its parsed value. |
float |
readFloat()
This method reads the float value (decimal number) starting at the
current position by
reading as many matching characters as available and returns its parsed value. |
long |
readLong(int maxDigits)
This method reads the long starting at the
current position by reading as many Latin
digits as available but at maximum the given maxDigits and returns its parsed value. |
String |
readUntil(char stop,
boolean acceptEof)
This method reads all
next characters until the given stop character or the end is reached. |
String |
readUntil(char stop,
boolean acceptEof,
char escape)
This method reads all
next characters until the given (un-escaped) stop character or the
end is reached. |
String |
readUntil(char stop,
boolean acceptEof,
CharScannerSyntax syntax)
This method reads all
next characters until the given stop character or the end of the
string to parse is reached. |
String |
readUntil(CharFilter filter,
boolean acceptEof)
This method reads all
next characters until the first character accepted by the given filter or the end is reached. |
String |
readWhile(CharFilter filter)
|
String |
readWhile(CharFilter filter,
int max)
|
void |
require(char expected)
This method verifies that the
current character is equal to the given expected character. |
void |
require(String expected,
boolean ignoreCase)
This method verifies that the
expected string gets consumed from this scanner with respect to
ignoreCase . |
boolean |
skipOver(String substring,
boolean ignoreCase)
This method reads all
next characters until the given substring has been detected. |
boolean |
skipOver(String substring,
boolean ignoreCase,
CharFilter stopFilter)
This method reads all
next characters until the given substring has been detected. |
boolean |
skipUntil(char stop)
This method skips all
next characters until the given stop character or the end is reached. |
boolean |
skipUntil(char stop,
char escape)
This method reads all
next characters until the given stop character or the end of the
string to parse is reached. |
int |
skipWhile(char c)
This method reads all
next characters that are identical to the character given by c . |
int |
skipWhile(CharFilter filter)
|
int |
skipWhile(CharFilter filter,
int max)
|
int getCurrentIndex()
0
. In other words this
method returns the number of characters that have already been consumed
.boolean hasNext()
true
if there is at least one character available, false
if the end has been reached.char next()
index
stepping to the next
character. You need to check
if a character is available before calling this method.char forceNext()
next()
this method reads the current
character and increments the
index
. If there is no character available
this method will do nothing
and returns 0
(the NULL character and NOT '0'
).0
if none is available
.char peek()
index
. You need to
check
if a character is available before calling this method.char forcePeek()
current
character without incrementing the
index
. If there is no character available
this method will return
0
(the NULL character and NOT '0'
).0
if none is available
.int readDigit()
next character
if it is a digit. Else the state remains unchanged.0
if '0'
) or -1
if the
current character
is no Latin digit.long readLong(int maxDigits) throws NumberFormatException
current position
by reading as many Latin
digits as available but at maximum the given maxDigits
and returns its parsed
value. +
or -
) to do so, scan them yourself before and negate the result
as needed.maxDigits
- is the maximum number of digits that will be read. The value has to be positive (greater than
zero). Use 19
or higher to be able to read any long number.NumberFormatException
- if the current current position
does NOT point to a
number.double readDouble() throws NumberFormatException
current position
by
reading as many matching characters as available and returns its parsed
value.
NumberFormatException
- if the current current position
does NOT point to a
number.float readFloat() throws NumberFormatException
current position
by
reading as many matching characters as available and returns its parsed
value.
NumberFormatException
- if the current current position
does NOT point to a
number.String read(int count)
next characters
given by count
and returns them as string.
If there are less characters available
the returned string will be shorter than count
and only contain the available characters.count
- is the number of characters to read. You may use Integer.MAX_VALUE
to read until the end of
data if the data-size is suitable.count
. Will
be the empty string if no character is available
at all.boolean expect(String expected, boolean ignoreCase)
next characters
as long as they equal to the according character of the
expected
string. expected
. Except for the latter circumstance, this method behaves like the following code:
read
(expected.length).equals[IgnoreCase](expected)
ATTENTION:expected
- is the expected string.ignoreCase
- - if true
the case of the characters is ignored when compared.true
if the expected
string was successfully consumed from this scanner, false
otherwise.boolean expectStrict(String expected, boolean ignoreCase)
expect(String, boolean)
but if the expected String is NOT completely present, no
character is consumed
and the state of the scanner remains unchanged.expected
- is the expected string.ignoreCase
- - if true
the case of the characters is ignored when compared.true
if the expected
string was successfully consumed from this scanner, false
otherwise.boolean expect(char expected)
current character
is equal to the given expected
character.
expected
- is the expected character.true
if the current character is the same as expected
, false
otherwise.void require(String expected, boolean ignoreCase) throws NlsParseException
expected
string gets consumed from this scanner with respect to
ignoreCase
. Otherwise an exception is thrown indicating the problem. if (!scanner.expectStrict
(expected, ignoreCase)) { throw newNlsParseException
(scanner.read(expected.length), expected); }
expected
- is the expected string.ignoreCase
- - if true
the case of the characters is ignored during comparison.NlsParseException
- if the expected
string was NOT found.void require(char expected) throws NlsParseException
current character
is equal to the given expected
character.
expected
- is the expected character.NlsParseException
- if the expected
character was NOT found.boolean skipUntil(char stop)
next characters
until the given stop
character or the end is reached.
If the stop
character was reached, this scanner will point to the next character after stop
when
this method returns.stop
- is the character to read until.true
if the first occurrence of the given stop
character has been passed, false
if
there is no such character.boolean skipUntil(char stop, char escape)
next characters
until the given stop
character or the end of the
string to parse is reached. In advance to skipUntil(char)
, this method will read over the stop
character if it is escaped with the given escape
character.stop
- is the character to read until.escape
- is the character used to escape the stop character (e.g. '\').true
if the first occurrence of the given stop
character has been passed, false
if
there is no such character.String readUntil(char stop, boolean acceptEof)
next characters
until the given stop
character or the end is reached.
current index
will point to the next character after
the (first) stop
character or to the end if NO such character exists.stop
- is the character to read until.acceptEof
- if true
EOF will be treated as stop
, too.stop
character or null
if there was no
stop
character and acceptEof
is false
.String readUntil(CharFilter filter, boolean acceptEof)
next characters
until the first character accepted
by the given filter
or the end is reached. current index
will point to the next character after
the first accepted
character or to the end if NO such character exists and
acceptEof
is true
. Otherwise, if null
is returned, the current
index
will remain unchanged.String readUntil(char stop, boolean acceptEof, char escape)
next characters
until the given (un-escaped) stop
character or the
end is reached. readUntil(char, boolean)
, this method allows that the stop
character may be used in
the input-string by adding the given escape
character. After the call of this method, the
current index
will point to the next character after the (first) stop
character
or to the end if NO such character exists. CharStreamScanner
scanner = getScanner(); doSomething(); char c = scanner.forceNext()
; if ((c == '"') || (c == '\'')) { char escape = c; // may also be something like '\' String quote = scanner.readUntil
(c, false, escape) } else { doOtherThings(); }
stop
- is the character to read until.acceptEof
- if true
EOF will be treated as stop
, too.escape
- is the character used to escape the stop
character. To add an occurrence of the
escape
character it has to be duplicated (occur twice). The escape
character may also be
equal to the stop
character. If other regular characters are escaped the escape
character is
simply ignored.stop
character or null
if there was no
stop
character and acceptEof
is false
.String readUntil(char stop, boolean acceptEof, CharScannerSyntax syntax)
next characters
until the given stop
character or the end of the
string to parse is reached. In advance to readUntil(char, boolean)
, this method will scan the input using
the given syntax
which e.g. allows to escape
the stop character. current index
will point to the next character after
the (first) stop
character or to the end of the string if NO such character exists.stop
- is the character to read until.acceptEof
- if true
EOF will be treated as stop
, too.syntax
- contains the characters specific for the syntax to read.stop
character or null
if there was no
stop
character.String readWhile(CharFilter filter)
next characters
that are accepted
by the
given filter
. current index
will point to the next character that
was NOT accepted
by the given filter
or to the end if NO such character
exists.filter
- is used to decide
which characters should be accepted.accepted
by the given filter
. Will be
the empty string if no character was accepted.skipWhile(CharFilter)
String readWhile(CharFilter filter, int max)
next characters
that are accepted
by the
given filter
. current index
will point to the next character that
was NOT accepted
by the given filter
. If the next max
characters or
the characters left until the end
of this scanner are accepted
,
only that amount of characters are skipped.filter
- is used to decide
which characters should be accepted.max
- is the maximum number of characters that should be read.accepted
by the given filter
limited
to the length of max
and the end
of this scanner. Will be the empty string if no
character was accepted.skipWhile(char)
boolean skipOver(String substring, boolean ignoreCase)
next characters
until the given substring
has been detected. current index
will point to the next character after
the first occurrence of substring
or to the end of the string if the given substring
was NOT found.
substring
- is the substring to search and skip over starting at the current index
.ignoreCase
- - if true
the case of the characters is ignored when compared with characters from
substring
.true
if the given substring
occurred and has been passed and false
if the end of
the string has been reached without any occurrence of the given substring
.boolean skipOver(String substring, boolean ignoreCase, CharFilter stopFilter)
next characters
until the given substring
has been detected. stop character
is detected by the given stopFilter
this method returns
false
pointing to the character next to that stop character. Otherwise after this method, the
current index
will point to the next character after the first occurrence of
substring
or to the end of the string if the given substring
was NOT found. substring
- is the substring to search and skip over starting at the current index
.ignoreCase
- - if true
the case of the characters is ignored when compared with characters from
substring
.stopFilter
- is the filter used to detect
stop characters. If such character
was detected, the skip is stopped and the parser points to the character after the stop character. The
substring
should NOT contain a stop character
.true
if the given substring
occurred and has been passed and false
if a stop
character has been detected or the end of the string has been reached without any occurrence of the given
substring
or stop character.int skipWhile(char c)
next characters
that are identical to the character given by c
. readWhile(' ')
to skip all blanks from the current
index
. After the call of this method, the current index
will point to the next
character that is different to c
or to the end if NO such character exists.c
- is the character to read over.int skipWhile(CharFilter filter)
next characters
that are accepted
by the
given filter
. current index
will point to the next character that
was NOT accepted
by the given filter
or to the end if NO such character
exists.filter
- is used to decide
which characters should be accepted.accepted
by the given filter
that have
been skipped.skipWhile(char)
int skipWhile(CharFilter filter, int max)
next characters
that are accepted
by the
given filter
. current index
will point to the next character that
was NOT accepted
by the given filter
. If the next max
characters or
the characters left until the end
of this scanner are accepted
,
only that amount of characters are skipped.filter
- is used to decide
which characters should be accepted.max
- is the maximum number of characters that should be skipped.skipWhile(char)
Copyright © 2001–2016 mmm-Team. All rights reserved.