java.lang.Object
io.github.mmm.scanner.AbstractCharStreamScanner
io.github.mmm.scanner.CharReaderScanner
- All Implemented Interfaces:
CharStreamScanner
Implementation of
CharStreamScanner that adapts a Reader to read and parse textual data.-
Field Summary
FieldsFields inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
buffer, limit, offsetFields inherited from interface io.github.mmm.scanner.CharStreamScanner
EOS -
Constructor Summary
ConstructorsConstructorDescriptionThe constructor.CharReaderScanner(int capacity) The constructor.CharReaderScanner(int capacity, Reader reader) The constructor.CharReaderScanner(Reader reader) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanexpectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip) booleanexpectStrict(String expected, boolean ignoreCase, boolean lookahead) This method acts asCharStreamScanner.expectUnsafe(String, boolean)but if the expected String is NOT completely present, no character isconsumedand the state of the scanner remains unchanged.
Attention:
This method requires lookahead.protected booleanfill()Fills the internalAbstractCharStreamScanner.bufferwith further data (if available from underlying source such as a stream/reader).intprotected booleanisEob()booleanisEos()booleanisEot()ATTENTION:voidprotected voidverifyLookahead(String substring) Methods inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
append, builder, consumeDecimal, eot, expectOne, expectOne, expectUnsafe, getAppended, getBufferParsed, getBufferToParse, hasNext, next, peek, read, readDigit, readJavaCharLiteral, readJavaStringLiteral, readLine, readLong, readUntil, readUntil, readUntil, readUntil, readUntil, readUntil, readWhile, require, reset, skip, skipOver, skipUntil, skipUntil, skipWhile, skipWhile, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.mmm.scanner.CharStreamScanner
expectStrict, expectStrict, expectUnsafe, readDigit, readDouble, readFloat, readJavaCharLiteral, readJavaStringLiteral, readLine, readUntil, readUntil, readWhile, require, require, requireOne, requireOne, requireOneOrMore, skipOver, skipOver, skipWhile, skipWhileAndPeek, skipWhileAndPeek
-
Field Details
-
position
protected int position- See Also:
-
-
Constructor Details
-
CharReaderScanner
public CharReaderScanner()The constructor. -
CharReaderScanner
The constructor.- Parameters:
reader- the (initial)Reader.
-
CharReaderScanner
public CharReaderScanner(int capacity) The constructor.- Parameters:
capacity- the buffer capacity.
-
CharReaderScanner
The constructor.- Parameters:
capacity- the buffer capacity.reader- the (initial)Reader.
-
-
Method Details
-
getPosition
public int getPosition()- Returns:
- the position in the sequence to scan or in other words the number of bytes that have been read. Will
initially be
0. Please note that this API is designed for scanning textual content (for parsers). Therefore we consider 2.1 terabyte as a suitablelimit.
-
setReader
- Parameters:
reader- the newReaderto set. May benullto entirely clear this buffer.
-
fill
protected boolean fill()Description copied from class:AbstractCharStreamScannerFills the internalAbstractCharStreamScanner.bufferwith further data (if available from underlying source such as a stream/reader). If theend of the streamhas not been reached, all buffers should be filled now.- Overrides:
fillin classAbstractCharStreamScanner- Returns:
trueif data was filled,falseifEOS.
-
isEos
public boolean isEos()- Overrides:
isEosin classAbstractCharStreamScanner- Returns:
trueif the end of stream (EOS) has been reached,falseotherwise. 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,EOThas 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:
isEobin classAbstractCharStreamScanner- Returns:
trueif end of buffer (EOB) or in other words no data is available after the currentAbstractCharStreamScanner.buffer,falseotherwise (e.g. if notEOS).
-
isEot
public boolean isEot()Description copied from class:AbstractCharStreamScannerATTENTION:- Overrides:
isEotin classAbstractCharStreamScanner- Returns:
trueif end of text (EOT) is known to have been reached,falseotherwise. 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 returningAbstractCharStreamScanner.hasNext()-1to signalEOSthis method may returnfalseeven though the next call ofAbstractCharStreamScanner.hasNext()may also returnfalse.
-
expectStrict
Description copied from interface:CharStreamScannerThis method acts asCharStreamScanner.expectUnsafe(String, boolean)but if the expected String is NOT completely present, no character isconsumedand the state of the scanner remains unchanged.
Attention:
This method requires lookahead. For implementations that are backed by an underlying stream (or reader) thelengthof the expectedStringshall not exceed the available lookahead size (buffer capacity given at construction time). Otherwise the method may fail.- Parameters:
expected- is the expected string.ignoreCase- - iftruethe case of the characters is ignored when compared.lookahead- - iftruethe state of the scanner remains unchanged even if the expectedStringhas been found,falseotherwise.- Returns:
trueif theexpectedstring was successfully consumed from this scanner,falseotherwise.
-
verifyLookahead
- Overrides:
verifyLookaheadin 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:
expectRestWithLookaheadin classAbstractCharStreamScanner- Parameters:
stopChars- the stopStringaschar[]. IfignoreCaseistruein lower case.ignoreCase- -trueto (also) compare chars inlower case,falseotherwise.appender- an optional lambda torunbefore shifting buffers to append data.skip- -trueto update buffers and offset such that on success this scanner points after the expected stopString,falseotherwise (to not consume any character in any case).- Returns:
trueif the stopString(stopChars) was found and consumed,falseotherwise (and no data consumed).- See Also:
-