- java.lang.Object
-
- io.github.mmm.scanner.AbstractCharStreamScanner
-
- All Implemented Interfaces:
CharStreamScanner
- Direct Known Subclasses:
CharReaderScanner
,CharSequenceScanner
public abstract class AbstractCharStreamScanner extends Object implements CharStreamScanner
Abstract implementation ofCharStreamScanner
.
ATTENTION:
This implementation and its sub-classes are NOT thread-safe and have no intention to be thread-safe.
-
-
Constructor Summary
Constructors Constructor Description AbstractCharStreamScanner(char[] buffer)
The constructor.AbstractCharStreamScanner(int capacity)
The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringBuilder
append(StringBuilder builder, int start, int end)
protected StringBuilder
builder(StringBuilder builder)
String
consumeDecimal()
Consumes the characters of a decimal number (double or float).protected String
eot(StringBuilder builder, boolean acceptEot)
boolean
expect(char expected)
This method checks that thecurrent character
is equal to the givenexpected
character.boolean
expect(String expected, boolean ignoreCase)
This method skips allnext characters
as long as they equal to the according character of theexpected
string.protected abstract boolean
expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)
protected boolean
fill()
Fills the internalbuffer
with further data (if available from underlying source such as a stream/reader).char
forceNext()
LikeCharStreamScanner.next()
this method reads the current character and increments the index.char
forcePeek()
This method reads the current character without incrementing the index.protected String
getAppended(StringBuilder builder, int start, int end)
boolean
hasNext()
This method determines if there is at least one more character available.protected boolean
isEob()
boolean
isEos()
boolean
isEot()
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 ofnext characters
given bycount
and returns them as string.int
readDigit(int radix)
This method reads thenext character
if it is a digit within the givenradix
.Character
readJavaCharLiteral(boolean tolerant)
Reads and parses a JavaCharacter
literal value according to JLS 3.10.6.String
readJavaStringLiteral(boolean tolerant)
Reads and parses a JavaString
literal value according to JLS 3.10.6.String
readLine(boolean trim)
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 givenmaxDigits
and returns itsparsed
value.String
readUntil(char stop, boolean acceptEot)
This method reads allnext characters
until the givenstop
character or the end is reached.String
readUntil(char stop, boolean acceptEot, char escape)
This method reads allnext characters
until the given (un-escaped)stop
character or the end is reached.String
readUntil(char stop, boolean acceptEot, CharScannerSyntax syntax)
This method reads allnext characters
until the givenstop
character or the end of the string to parse is reached.String
readUntil(CharFilter filter, boolean acceptEot)
This method reads allnext characters
until the first characteraccepted
by the givenfilter
or the end is reached.String
readUntil(CharFilter filter, boolean acceptEot, CharScannerSyntax syntax)
This method reads allnext characters
until the givenCharFilter
accepts
the current character as stop character or the end of text (EOT) is reached.String
readUntil(CharFilter stopFilter, boolean acceptEot, String stop, boolean ignoreCase, boolean trim)
This method reads allnext characters
until the first characteraccepted
by the givenfilter
, the givenstop
String
or the end is reached.String
readWhile(CharFilter filter, int max)
void
require(char expected)
This method verifies that thecurrent character
is equal to the givenexpected
character.void
require(String expected, boolean ignoreCase)
This method verifies that theexpected
string gets consumed from this scanner with respect toignoreCase
.protected void
reset()
Resets the internal state.int
skip(int count)
This method skips the number ofnext characters
given bycount
.boolean
skipOver(String substring, boolean ignoreCase, CharFilter stopFilter)
This method consumes allnext characters
until the givensubstring
has been detected, a character wasaccepted
by the givenCharFilter
orEOT
was reached.
After the call of this method this scanner will point to the next character after the first occurrence ofsubstring
, to the stop character or toEOT
.boolean
skipUntil(char stop)
This method skips allnext characters
until the givenstop
character or the end is reached.boolean
skipUntil(char stop, char escape)
This method reads allnext characters
until the givenstop
character or the end of the string to parse is reached.int
skipWhile(char c)
This method reads allnext characters
that are identical to the character given byc
.int
skipWhile(CharFilter filter, int max)
String
toString()
protected void
verifyLookahead(String substring)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.scanner.CharStreamScanner
expect, expectStrict, expectStrict, readDigit, readDouble, readFloat, readJavaCharLiteral, readJavaStringLiteral, readLine, readUntil, readUntil, readWhile, skipOver, skipOver, skipWhile, skipWhileAndPeek, skipWhileAndPeek
-
-
-
-
Field Detail
-
buffer
protected char[] buffer
The internal buffer with character data.
-
offset
protected int offset
The start position in thebuffer
from where reading operations consumer data from.
-
limit
protected int limit
-
-
Constructor Detail
-
AbstractCharStreamScanner
public AbstractCharStreamScanner(int capacity)
The constructor.- Parameters:
capacity
- the capacity of the internal buffer inchar
s.
-
AbstractCharStreamScanner
public AbstractCharStreamScanner(char[] buffer)
The constructor.- Parameters:
buffer
- the internalchar[]
buffer.
-
-
Method Detail
-
reset
protected void reset()
Resets the internal state.
-
builder
protected StringBuilder builder(StringBuilder builder)
- Parameters:
builder
- a localStringBuilder
variable to be allocated lazily.- Returns:
- the given
StringBuilder
if notnull
or otherwise a reusedStringBuilder
instance that has been reset.
-
append
protected StringBuilder append(StringBuilder builder, int start, int end)
- Parameters:
builder
- a localStringBuilder
variable to be allocated lazily.start
- the start index in the underlying buffer to append.end
- the limit index in the underlying buffer pointing to the next position after the last character to append.- Returns:
- the given
StringBuilder
if notnull
or otherwise a reusedStringBuilder
instance that has been reset.
-
getAppended
protected String getAppended(StringBuilder builder, int start, int end)
- Parameters:
builder
- the localStringBuilder
instance where data may already have been appended to. May benull
.start
- the start index in the underlying buffer to append.end
- the limit index in the underlying buffer pointing to the next position after the last character to append.- Returns:
- the
String
with the underlying buffer data fromstart
toend-1
potentially appended to the givenStringBuilder
if notnull
.
-
hasNext
public boolean hasNext()
Description copied from interface:CharStreamScanner
This method determines if there is at least one more character available.- Specified by:
hasNext
in interfaceCharStreamScanner
- Returns:
true
if there is at least one character available,false
if the end of text (EOT) has been reached.
-
isEos
public boolean isEos()
- Specified by:
isEos
in interfaceCharStreamScanner
- Returns:
true
if the end of stream (EOS) has been reached,false
otherwise. Iftrue
(EOS) the internal buffer contains the entire rest of the data to scan in memory. If then also all data is consumed from the buffer,EOT
has been reached. For instances of that are not backed by an underlying stream of data (likeCharSequenceScanner
) this method will always returntrue
.
-
isEob
protected boolean isEob()
-
isEot
public boolean isEot()
- Specified by:
isEot
in interfaceCharStreamScanner
- Returns:
true
if end of text (EOT) is known to have been reached,false
otherwise. The returned result will be almost the same as!
but this method will not modify the state of this scanner (read additional data, modify buffers, etc.). However, if the underlying stream is already consumed without returningCharStreamScanner.hasNext()
-1
to signalEOS
this method may returnfalse
even though the next call ofCharStreamScanner.hasNext()
may also returnfalse
.
-
fill
protected boolean fill()
Fills the internalbuffer
with further data (if available from underlying source such as a stream/reader). If theend of the stream
has not been reached, all buffers should be filled now.- Returns:
true
if data was filled,false
ifEOS
.
-
next
public char next()
Description copied from interface:CharStreamScanner
This method reads the current character and increments the index stepping to the next character. You need tocheck
if a character is available before calling this method.- Specified by:
next
in interfaceCharStreamScanner
- Returns:
- the current character.
-
forceNext
public char forceNext()
Description copied from interface:CharStreamScanner
LikeCharStreamScanner.next()
this method reads the current character and increments the index. If there is no characteravailable
this method will do nothing but return'\0'
(the NULL character and NOT'0'
).- Specified by:
forceNext
in interfaceCharStreamScanner
- Returns:
- the current character or
0
if none isavailable
.
-
peek
public char peek()
Description copied from interface:CharStreamScanner
This method reads the current character without incrementing the index. You need tocheck
if a character is available before calling this method.- Specified by:
peek
in interfaceCharStreamScanner
- Returns:
- the current character.
-
forcePeek
public char forcePeek()
Description copied from interface:CharStreamScanner
This method reads the current character without incrementing the index. If there is no characteravailable
this method will return0
(the NULL character and NOT'0'
).- Specified by:
forcePeek
in interfaceCharStreamScanner
- Returns:
- the current character or
0
if none isavailable
.
-
eot
protected String eot(StringBuilder builder, boolean acceptEot)
- Parameters:
builder
- the optionalStringBuilder
where data may have already been appended.acceptEot
-true
to acceptEOT
,false
otherwise.- Returns:
null
ifacceptEot
isfalse
, otherwise theString
from the givenStringBuilder
or the emptyString
in case theStringBuilder
wasnull
.
-
readUntil
public String readUntil(char stop, boolean acceptEot)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the givenstop
character or the end is reached.
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.- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
stop
- is the character to read until.acceptEot
- iftrue
EOT
will be treated asstop
, too.- Returns:
- the string with all read characters excluding the
stop
character ornull
if there was nostop
character andacceptEot
isfalse
.
-
readUntil
public String readUntil(char stop, boolean acceptEot, CharScannerSyntax syntax)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the givenstop
character or the end of the string to parse is reached. In advance toCharStreamScanner.readUntil(char, boolean)
, this method will scan the input using the givensyntax
which e.g. allows toescape
the stop 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 of the string if NO such character exists.- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
stop
- is the character to read until.acceptEot
- iftrue
EOT
will be treated asstop
, too.syntax
- contains the characters specific for the syntax to read.- Returns:
- the string with all read characters excluding the
stop
character ornull
if there was nostop
character. - See Also:
CharStreamScanner.readUntil(CharFilter, boolean, CharScannerSyntax)
-
readUntil
public String readUntil(CharFilter filter, boolean acceptEot, CharScannerSyntax syntax)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the givenCharFilter
accepts
the current character as stop character or the end of text (EOT) is reached. In advance toCharStreamScanner.readUntil(char, boolean)
, this method will scan the input using the givensyntax
which e.g. allows toescape
the stop 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 of the string if NO such character exists.- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
filter
- is used todecide
where to stop.acceptEot
- iftrue
EOT
will be treated asstop
, too.syntax
- contains the characters specific for the syntax to read.- Returns:
- the string with all read characters excluding the
stop
character ornull
if there was nostop
character. - See Also:
CharStreamScanner.readUntil(char, boolean, CharScannerSyntax)
-
readUntil
public String readUntil(char stop, boolean acceptEot, char escape)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the given (un-escaped)stop
character or the end is reached.
In advance toCharStreamScanner.readUntil(char, boolean)
, this method allows that thestop
character may be used in the input-string by adding the givenescape
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.
This method is especially useful when quoted strings should be parsed. E.g.:CharStreamScanner
scanner = getScanner(); doSomething(); char c = scanner.CharStreamScanner.forceNext()
; if ((c == '"') || (c == '\'')) { char escape = c; // may also be something like '\' String quote = scanner.readUntil
(c, false, escape) } else { doOtherThings(); }- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
stop
- is the character to read until.acceptEot
- iftrue
EOT
will be treated asstop
, too.escape
- is the character used to escape thestop
character. To add an occurrence of theescape
character it has to be duplicated (occur twice). Theescape
character may also be equal to thestop
character. If other regular characters are escaped theescape
character is simply ignored.- Returns:
- the string with all read characters excluding the
stop
character ornull
if there was nostop
character andacceptEot
isfalse
.
-
readUntil
public String readUntil(CharFilter filter, boolean acceptEot)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the first characteraccepted
by the givenfilter
or the end is reached.
After the call of this method, the current index will point to the firstaccepted
stop character or to the end if NO such character exists.- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
filter
- is used todecide
where to stop.acceptEot
- iftrue
ifEOT
should be treated like thestop
character and the rest of the text will be returned,false
otherwise (to returnnull
ifEOT
was reached and the scanner has been consumed).- Returns:
- the string with all read characters not
accepted
by the givenCharFilter
ornull
if there was noaccepted
character andacceptEot
isfalse
.
-
readUntil
public String readUntil(CharFilter stopFilter, boolean acceptEot, String stop, boolean ignoreCase, boolean trim)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the first characteraccepted
by the givenfilter
, the givenstop
String
or the end is reached.
After the call of this method, the current index will point to the firstaccepted
stop character, or to the first character of the givenstop
String
or to the end if NO such character exists.- Specified by:
readUntil
in interfaceCharStreamScanner
- Parameters:
stopFilter
- is used todecide
where to stop.acceptEot
- iftrue
ifEOT
should be treated like thestop
character and the rest of the text will be returned,false
otherwise (to returnnull
ifEOT
was reached and the scanner has been consumed).stop
- theString
where to stop consuming data. Should be at least two characters long (otherwise accept byCharFilter
instead).ignoreCase
- - iftrue
the case of the characters is ignored when compared with characters fromstop
String
.trim
- -true
if the result should betrimmed
,false
otherwise.- Returns:
- the string with all read characters not
accepted
by the givenCharFilter
or until the givenstop
String
was detected. IfEOT
was reached without a stop signal the entire rest of the data is returned ornull
ifacceptEot
isfalse
. Thre result will betrimmed
iftrim
istrue
.
-
verifyLookahead
protected void verifyLookahead(String substring)
- Parameters:
substring
- the substring to match without consuming what requires a lookahead.
-
expectRestWithLookahead
protected abstract boolean expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)
- Parameters:
stopChars
- the stopString
aschar[]
. IfignoreCase
istrue
in lower case.ignoreCase
- -true
to (also) compare chars inlower case
,false
otherwise.appender
- an optional lambda torun
before shifting buffers to append data.skip
- -true
to update buffers and offset such that on success this scanner points after the expected stopString
,false
otherwise (to not consume any character in any case).- Returns:
true
if the stopString
(stopChars
) was found and consumed,false
otherwise (and no data consumed).- See Also:
CharStreamScanner.readUntil(CharFilter, boolean, String, boolean)
,skipOver(String, boolean, CharFilter)
-
require
public void require(char expected)
Description copied from interface:CharStreamScanner
This method verifies that thecurrent character
is equal to the givenexpected
character.
If the current character was as expected, the parser points to the next character. Otherwise an exception is thrown indicating the problem.- Specified by:
require
in interfaceCharStreamScanner
- Parameters:
expected
- is the expected character.
-
require
public void require(String expected, boolean ignoreCase)
Description copied from interface:CharStreamScanner
This method verifies that theexpected
string gets consumed from this scanner with respect toignoreCase
. Otherwise an exception is thrown indicating the problem.
This method behaves functionally equivalent to the following code:if (!scanner.
expectStrict
(expected, ignoreCase)) { throw newIllegalStateException
(...); }- Specified by:
require
in interfaceCharStreamScanner
- Parameters:
expected
- is the expected string.ignoreCase
- - iftrue
the case of the characters is ignored during comparison.
-
expect
public boolean expect(char expected)
Description copied from interface:CharStreamScanner
This method checks that thecurrent character
is equal to the givenexpected
character.
If the current character was as expected, the parser points to the next character. Otherwise its position will remain unchanged.- Specified by:
expect
in interfaceCharStreamScanner
- Parameters:
expected
- is the expected character.- Returns:
true
if the current character is the same asexpected
,false
otherwise.
-
expect
public boolean expect(String expected, boolean ignoreCase)
Description copied from interface:CharStreamScanner
This method skips allnext characters
as long as they equal to the according character of theexpected
string.
If a character differs this method stops and the parser points to the first character that differs fromexpected
. Except for the latter circumstance, this method behaves like the following code:read
(expected.length).equals[IgnoreCase](expected)
Be aware that if already the first character differs, this method will NOT change the state of the scanner. So take care NOT to produce infinity loops.- Specified by:
expect
in interfaceCharStreamScanner
- Parameters:
expected
- is the expected string.ignoreCase
- - iftrue
the case of the characters is ignored when compared.- Returns:
true
if theexpected
string was successfully consumed from this scanner,false
otherwise.
-
readLine
public String readLine(boolean trim)
- Specified by:
readLine
in interfaceCharStreamScanner
- Parameters:
trim
- -true
if the result should betrimmed
,false
otherwise.- Returns:
- a
String
with the data until the end of the current line (trimmed
iftrim
istrue
) orEOT
. Will benull
if the EOT has already been reached andCharStreamScanner.hasNext()
returnsfalse
.
-
readJavaStringLiteral
public String readJavaStringLiteral(boolean tolerant)
Description copied from interface:CharStreamScanner
Reads and parses a JavaString
literal value according to JLS 3.10.6.
As a complex example for the input "Hi \"\176\477\579•∑\"\n" this scanner would return theString
outputHi "~'7/9•∑"
followed by a newline character.- Specified by:
readJavaStringLiteral
in interfaceCharStreamScanner
- Parameters:
tolerant
- -true
if invalid escape sequences should be tolerated (as '?'),false
to throw an exception in such case.- Returns:
- the parsed Java
String
literal value ornull
if not pointing to aString
literal.
-
readJavaCharLiteral
public Character readJavaCharLiteral(boolean tolerant)
Description copied from interface:CharStreamScanner
Reads and parses a JavaCharacter
literal value according to JLS 3.10.6.
Examples are given in the following table:literal result comment 'a'
a regular char '\''
' escaped char '\176'
~ escaped octal representation '•'
• escaped unicode representation - Specified by:
readJavaCharLiteral
in interfaceCharStreamScanner
- Parameters:
tolerant
- -true
if an invalid char literal should be tolerated (as '?'),false
to throw an exception in such case.- Returns:
- the parsed Java
String
literal value ornull
if not pointing to aString
literal.
-
read
public String read(int count)
Description copied from interface:CharStreamScanner
This method reads the number ofnext characters
given bycount
and returns them as string. If there are less charactersavailable
the returned string will be shorter thancount
and only contain the available characters.- Specified by:
read
in interfaceCharStreamScanner
- Parameters:
count
- is the number of characters to read. You may useInteger.MAX_VALUE
to read until the end of data if the data-size is suitable.- Returns:
- a string with the given number of characters or all available characters if less than
count
. Will be the empty string if no character isavailable
at all.
-
readDigit
public int readDigit(int radix)
Description copied from interface:CharStreamScanner
This method reads thenext character
if it is a digit within the givenradix
. Else the state remains unchanged.- Specified by:
readDigit
in interfaceCharStreamScanner
- Parameters:
radix
- the radix that defines the range of the digits. SeeInteger.parseInt(String, int)
. E.g.10
to read any Latin digit (seeCharStreamScanner.readDigit()
),8
to read octal digit,16
to read hex decimal digits.- Returns:
- the numeric value of the next digit within the given
radix
or-1
if thecurrent character
is no such digit.
-
consumeDecimal
public String consumeDecimal()
Description copied from interface:CharStreamScanner
Consumes the characters of a decimal number (double or float).- Specified by:
consumeDecimal
in interfaceCharStreamScanner
- Returns:
- the decimal number as
String
.
-
readLong
public long readLong(int maxDigits) throws NumberFormatException
Description copied from interface:CharStreamScanner
This method reads the long starting at the current position by reading as many Latin digits as available but at maximum the givenmaxDigits
and returns itsparsed
value.
ATTENTION:
This method does NOT treat signs (+
or-
) to do so, scan them yourself before and negate the result as needed.- Specified by:
readLong
in interfaceCharStreamScanner
- Parameters:
maxDigits
- is the maximum number of digits that will be read. The value has to be positive (greater than zero). Use19
or higher to be able to read any long number.- Returns:
- the parsed number.
- Throws:
NumberFormatException
- if the current current position does NOT point to a number.
-
skip
public int skip(int count)
Description copied from interface:CharStreamScanner
This method skips the number ofnext characters
given bycount
.- Specified by:
skip
in interfaceCharStreamScanner
- Parameters:
count
- is the number of characters to skip. You may useInteger.MAX_VALUE
to read until the end of data if the data-size is suitable.- Returns:
- a to total number of characters that have been skipped. Typically equal to
count
. Will be less in case theend of the stream
was reached.
-
skipUntil
public boolean skipUntil(char stop)
Description copied from interface:CharStreamScanner
This method skips allnext characters
until the givenstop
character or the end is reached. If thestop
character was reached, this scanner will point to the next character afterstop
when this method returns.- Specified by:
skipUntil
in interfaceCharStreamScanner
- Parameters:
stop
- is the character to read until.- Returns:
true
if the first occurrence of the givenstop
character has been passed,false
if there is no such character.
-
skipUntil
public boolean skipUntil(char stop, char escape)
Description copied from interface:CharStreamScanner
This method reads allnext characters
until the givenstop
character or the end of the string to parse is reached. In advance toCharStreamScanner.skipUntil(char)
, this method will read over thestop
character if it is escaped with the givenescape
character.- Specified by:
skipUntil
in interfaceCharStreamScanner
- Parameters:
stop
- is the character to read until.escape
- is the character used to escape the stop character (e.g. '\').- Returns:
true
if the first occurrence of the givenstop
character has been passed,false
if there is no such character.
-
skipWhile
public int skipWhile(char c)
Description copied from interface:CharStreamScanner
This method reads allnext characters
that are identical to the character given byc
.
E.g. usereadWhile(' ')
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 the given characterc
or to the end if NO such character exists.- Specified by:
skipWhile
in interfaceCharStreamScanner
- Parameters:
c
- is the character to read over.- Returns:
- the number of characters that have been skipped.
-
skipWhile
public int skipWhile(CharFilter filter, int max)
Description copied from interface:CharStreamScanner
This method reads allnext characters
that areaccepted
by the givenfilter
.
After the call of this method, the current index will point to the next character that was NOTaccepted
by the givenfilter
. If the nextmax
characters or the characters left until theend
of this scanner areaccepted
, only that amount of characters are skipped.- Specified by:
skipWhile
in interfaceCharStreamScanner
- Parameters:
filter
- is used todecide
which characters should be accepted.max
- is the maximum number of characters that may be skipped.- Returns:
- the number of skipped characters.
- See Also:
CharStreamScanner.skipWhile(char)
-
skipOver
public boolean skipOver(String substring, boolean ignoreCase, CharFilter stopFilter)
Description copied from interface:CharStreamScanner
This method consumes allnext characters
until the givensubstring
has been detected, a character wasaccepted
by the givenCharFilter
orEOT
was reached.
After the call of this method this scanner will point to the next character after the first occurrence ofsubstring
, to the stop character or toEOT
.- Specified by:
skipOver
in interfaceCharStreamScanner
- Parameters:
substring
- is the substring to search and skip over starting at the current index.ignoreCase
- - iftrue
the case of the characters is ignored when compared with characters fromsubstring
.stopFilter
- is the filter used todetect
stop characters. If such character was detected, the skip is stopped and the parser points to the character after the stop character. Thesubstring
should NOT contain astop character
.- Returns:
true
if the givensubstring
occurred and has been passed andfalse
if a stop character has been detected or the end of the string has been reached without any occurrence of the givensubstring
or stop character.
-
readWhile
public String readWhile(CharFilter filter, int max)
Description copied from interface:CharStreamScanner
This method reads allnext characters
that areaccepted
by the givenfilter
.
After the call of this method, the current index will point to the next character that was NOTaccepted
by the givenfilter
. If the nextmax
characters or the characters left until theend
of this scanner areaccepted
, only that amount of characters are skipped.- Specified by:
readWhile
in interfaceCharStreamScanner
- Parameters:
filter
- is used todecide
which characters should be accepted.max
- is the maximum number of characters that should be read.- Returns:
- a string with all characters
accepted
by the givenfilter
limited to the length ofmax
and theend
of this scanner. Will be the empty string if no character was accepted. - See Also:
CharStreamScanner.skipWhile(char)
-
-