- java.lang.Object
-
- io.github.mmm.scanner.AbstractCharStreamScanner
-
- io.github.mmm.scanner.CharReaderScanner
-
- All Implemented Interfaces:
CharStreamScanner
public class CharReaderScanner extends AbstractCharStreamScanner
Implementation ofCharStreamScanner
that adapts aReader
to read and parse textual data.
-
-
Field Summary
-
Fields inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
buffer, limit, offset
-
-
Constructor Summary
Constructors Constructor Description CharReaderScanner()
The constructor.CharReaderScanner(int capacity)
The constructor.CharReaderScanner(int capacity, Reader reader)
The constructor.CharReaderScanner(Reader reader)
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)
boolean
expectStrict(String expected, boolean ignoreCase)
This method acts asCharStreamScanner.expect(String, boolean)
but if the expected String is NOT completely present, no character isconsumed
and the state of the scanner remains unchanged.
Attention:
This method requires lookahead.protected boolean
fill()
Fills the internalAbstractCharStreamScanner.buffer
with further data (if available from underlying source such as a stream/reader).protected boolean
isEob()
boolean
isEos()
boolean
isEot()
void
setReader(Reader reader)
Resets this buffer for reuse with a newReader
.protected void
verifyLookahead(String substring)
-
Methods inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
append, builder, consumeDecimal, eot, expect, expect, forceNext, forcePeek, getAppended, hasNext, next, peek, read, readDigit, readJavaCharLiteral, readJavaStringLiteral, readLine, readLong, readUntil, readUntil, readUntil, readUntil, readUntil, readUntil, readWhile, require, require, reset, skip, skipOver, skipUntil, skipUntil, skipWhile, skipWhile, toString
-
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, readDigit, readDouble, readFloat, readJavaCharLiteral, readJavaStringLiteral, readLine, readUntil, readUntil, readWhile, skipOver, skipOver, skipWhile, skipWhileAndPeek, skipWhileAndPeek
-
-
-
-
Constructor Detail
-
CharReaderScanner
public CharReaderScanner()
The constructor.
-
CharReaderScanner
public CharReaderScanner(Reader reader)
The constructor.- Parameters:
reader
- the (initial)Reader
.
-
CharReaderScanner
public CharReaderScanner(int capacity)
The constructor.- Parameters:
capacity
- the buffer capacity.
-
-
Method Detail
-
setReader
public void setReader(Reader reader)
Resets this buffer for reuse with a newReader
.- Parameters:
reader
- the newReader
to set. May benull
to entirely clear this buffer.
-
fill
protected boolean fill()
Description copied from class:AbstractCharStreamScanner
Fills the internalAbstractCharStreamScanner.buffer
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.- Overrides:
fill
in classAbstractCharStreamScanner
- Returns:
true
if data was filled,false
ifEOS
.
-
isEos
public boolean isEos()
- Specified by:
isEos
in interfaceCharStreamScanner
- Overrides:
isEos
in classAbstractCharStreamScanner
- 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()
- Overrides:
isEob
in classAbstractCharStreamScanner
- Returns:
true
if end of buffer (EOB) or in other words no data is available after the currentAbstractCharStreamScanner.buffer
,false
otherwise (e.g. if notEOS
).
-
isEot
public boolean isEot()
- Specified by:
isEot
in interfaceCharStreamScanner
- Overrides:
isEot
in classAbstractCharStreamScanner
- 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
.
-
expectStrict
public boolean expectStrict(String expected, boolean ignoreCase)
Description copied from interface:CharStreamScanner
This method acts asCharStreamScanner.expect(String, boolean)
but if the expected String is NOT completely present, no character isconsumed
and the state of the scanner remains unchanged.
Attention:
This method requires lookahead. For implementations that are backed by an underlying stream (or reader) thelength
of the expectedString
shall not exceed the available lookahead size (buffer capacity given at construction time). Otherwise the method may fail.- 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.
-
verifyLookahead
protected void verifyLookahead(String substring)
- Overrides:
verifyLookahead
in classAbstractCharStreamScanner
- Parameters:
substring
- the substring to match without consuming what requires a lookahead.
-
expectRestWithLookahead
protected boolean expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)
- Specified by:
expectRestWithLookahead
in classAbstractCharStreamScanner
- 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)
,AbstractCharStreamScanner.skipOver(String, boolean, CharFilter)
-
-