java.lang.Object
io.github.mmm.scanner.AbstractCharStreamScanner
- All Implemented Interfaces:
TextFormatProcessor,TextPosition,CharStreamScanner,AutoCloseable
- Direct Known Subclasses:
CharReaderScanner,CharSequenceScanner
Abstract implementation of
ATTENTION:
This implementation and its sub-classes are NOT thread-safe and have no intention to be thread-safe.
CharStreamScanner.ATTENTION:
This implementation and its sub-classes are NOT thread-safe and have no intention to be thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected char[]The internal buffer with character data.protected intprotected intThe limit in thebuffer.protected intprotected intThe start position in thebufferfrom where reading operations consumer data from.Fields inherited from interface io.github.mmm.scanner.CharStreamScanner
EOS -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCharStreamScanner(char[] buffer, TextFormatMessageHandler messageHandler) The constructor.AbstractCharStreamScanner(char[] buffer, TextFormatMessageHandler messageHandler, int line, int column) The constructor.AbstractCharStreamScanner(int capacity, TextFormatMessageHandler messageHandler) The constructor.AbstractCharStreamScanner(int capacity, TextFormatMessageHandler messageHandler, int line, int column) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMessage(TextFormatMessage message) protected StringBuilderappend(StringBuilder builder, int start, int end) protected StringBuilderbuilder(StringBuilder builder) protected Stringeot(StringBuilder builder, boolean acceptEot) booleanexpectOne(char expected, boolean warning) This method checks if thenext characteris equal to the givenexpectedcharacter.booleanexpectOne(CharFilter expected) protected abstract booleanexpectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip) booleanexpectUnsafe(String expected, boolean ignoreCase) This method skips allnext charactersas long as they equal to the according character of theexpectedstring.protected booleanfill()protected StringgetAppended(StringBuilder builder, int start, int end) intintgetLine()protected charhandleChar(char c) booleanhasNext()This method determines if there is at least one more character available.protected booleanisEob()protected booleanisEos()protected booleanisEot()ATTENTION:charnext()This method reads the current character from the stream and increments the index stepping to the next character.charpeek()This method reads the current character withoutconsumingcharacters and will therefore not change the state of this scanner.read(int count) This method reads the number ofnext charactersgiven bycountand returns them as string.voidread(int count, StringBuilder builder) This method reads the number ofnext charactersgiven bycountandappendsthem to the givenStringBuilder.intreadDigit(int radix) This method reads thenext characterif it is a digit within the givenradix.readDouble(CharScannerRadixHandler radixMode) This method reads the double value (decimal number) starting at the current position by reading as many matching characters as available and returns itsparsedvalue.readFloat(CharScannerRadixHandler radixMode) readInteger(CharScannerRadixHandler radixMode) readJavaCharLiteral(TextFormatMessageType severity) Reads and parses a JavaCharacterliteral value according to JLS 3.10.6.Reads a JavaNumberliteral (e.g.readJavaStringLiteral(TextFormatMessageType severity) Reads and parses a JavaStringliteral value according to JLS 3.10.6.readLine(boolean trim) readLong(CharScannerRadixHandler radixMode) voidreadNumber(CharScannerNumberParser numberParser) Generic way to read and parse any kind ofNumber.longreadUnsignedLong(int maxDigits) This method reads the long starting at the current position by reading as many Latin digits as available but at maximum the givenmaxDigitsand returns itsparsedvalue.readUntil(char stop, boolean acceptEot) This method reads allnext charactersuntil the givenstopcharacter or the end is reached.readUntil(char stop, boolean acceptEot, char escape) This method reads allnext charactersuntil the given (un-escaped)stopcharacter or the end is reached.readUntil(char stop, boolean acceptEot, CharScannerSyntax syntax) This method reads allnext charactersuntil the givenstopcharacter or the end of the string to parse is reached.readUntil(CharFilter filter, boolean acceptEot) This method reads allnext charactersuntil the first characteracceptedby the givenfilteror the end is reached.readUntil(CharFilter filter, boolean acceptEot, CharScannerSyntax syntax) This method reads allnext charactersuntil the givenCharFilteracceptsthe current character as stop character or the end of data is reached.readUntil(CharFilter stopFilter, boolean acceptEot, String stop, boolean ignoreCase, boolean trim) This method reads allnext charactersuntil the first characteracceptedby the givenfilter, the givenstopStringor the end is reached.readWhile(CharFilter filter, int min, int max) voidThis method verifies that theexpectedstring gets consumed from this scanner with respect toignoreCase.protected voidrequireMin(int actual, int min, CharFilter filter) protected voidreset()Resets the internal state.protected voidsetOffset(int newOffset) intskip(int count) This method skips the number ofnext charactersgiven bycount.intbooleanskipOver(String substring, boolean ignoreCase, CharFilter stopFilter) This method consumes allnext charactersuntil the givensubstringhas been detected, a character wasacceptedby the givenCharFilteror the end of data 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 to end of data.booleanskipUntil(char stop) This method skips allnext charactersuntil the givenstopcharacter or the end is reached.booleanskipUntil(char stop, char escape) This method reads allnext charactersuntil the givenstopcharacter or the end of the string to parse is reached.intskipWhile(char c) This method reads allnext charactersthat are identical to the character given byc.intskipWhile(CharFilter filter, int max) toString()protected voidverifyLookahead(int length) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.mmm.scanner.CharStreamScanner
close, expect, expect, expect, expect, expect, expectOne, expectUnsafe, getPosition, peek, peekString, peekUntil, peekWhile, readBoolean, readBoolean, readBoolean, readDigit, readDouble, readFloat, readInteger, readJavaCharLiteral, readJavaStringLiteral, readLine, readLong, readUntil, readUntil, readUntil, readWhile, require, require, requireOne, requireOne, requireOneOrMore, skipOver, skipOver, skipWhile, skipWhileAndPeek, skipWhileAndPeekMethods inherited from interface io.github.mmm.base.text.TextFormatProcessor
addError, addInfo, addMessage, addWarning
-
Field Details
-
buffer
protected char[] bufferThe internal buffer with character data. -
offset
protected int offsetThe start position in thebufferfrom where reading operations consumer data from. -
limit
protected int limit -
line
protected int line- See Also:
-
column
protected int column- See Also:
-
-
Constructor Details
-
AbstractCharStreamScanner
The constructor.- Parameters:
capacity- the capacity of the internal buffer inchars.messageHandler- theTextFormatMessageHandler.
-
AbstractCharStreamScanner
public AbstractCharStreamScanner(int capacity, TextFormatMessageHandler messageHandler, int line, int column) The constructor.- Parameters:
capacity- the capacity of the internal buffer inchars.messageHandler- theTextFormatMessageHandler.line- the initialline.column- the initialcolumn.
-
AbstractCharStreamScanner
The constructor.- Parameters:
buffer- the internalchar[]buffer.messageHandler- theTextFormatMessageHandler.
-
AbstractCharStreamScanner
public AbstractCharStreamScanner(char[] buffer, TextFormatMessageHandler messageHandler, int line, int column) The constructor.- Parameters:
buffer- the internalchar[]buffer.messageHandler- theTextFormatMessageHandler.line- the initialline.column- the initialcolumn.
-
-
Method Details
-
getLine
public int getLine()- Specified by:
getLinein interfaceTextPosition
-
getColumn
public int getColumn()- Specified by:
getColumnin interfaceTextPosition
-
addMessage
- Specified by:
addMessagein interfaceTextFormatProcessor
-
getMessages
- Specified by:
getMessagesin interfaceTextFormatProcessor
-
reset
protected void reset()Resets the internal state. -
builder
- Parameters:
builder- a localStringBuildervariable to be allocated lazily.- Returns:
- the given
StringBuilderif notnullor otherwise a reusedStringBuilderinstance that has been reset.
-
append
- Parameters:
builder- a localStringBuildervariable 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
StringBuilderif notnullor otherwise a reusedStringBuilderinstance that has been reset.
-
getAppended
- Parameters:
builder- the localStringBuilderinstance 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
Stringwith the underlying buffer data fromstarttoend-1potentially appended to the givenStringBuilderif notnull.
-
hasNext
public boolean hasNext()Description copied from interface:CharStreamScannerThis method determines if there is at least one more character available.- Specified by:
hasNextin interfaceCharStreamScanner- Returns:
trueif there is at least one character available,falseif the end of data has been reached.
-
isEos
protected boolean isEos()- 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() -
isEot
protected boolean isEot()ATTENTION:- 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 returninghasNext()-1to signalEOSthis method may returnfalseeven though the next call ofhasNext()may also returnfalse.
-
fill
protected boolean fill()Consumes all remaining data in the internalbufferand fills thebufferwith 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.- Returns:
trueif data was filled,falseifEOS.
-
next
public char next()Description copied from interface:CharStreamScannerThis method reads the current character from the stream and increments the index stepping to the next character. You shouldcheckif a character is available before calling this method. Otherwise if your stream may contain the NUL character ('\0') you can not distinguish if the end of the stream was reached or you actually read the NUL character.- Specified by:
nextin interfaceCharStreamScanner- Returns:
- the
CharStreamScanner.next()character orCharStreamScanner.EOSif none isavailable.
-
handleChar
protected char handleChar(char c) - Parameters:
c- the character to handle.- Returns:
- the given character.
-
setOffset
protected void setOffset(int newOffset) -
peek
public char peek()Description copied from interface:CharStreamScannerThis method reads the current character withoutconsumingcharacters and will therefore not change the state of this scanner.- Specified by:
peekin interfaceCharStreamScanner- Returns:
- the current character or
CharStreamScanner.EOSif none isavailable.
-
eot
- Parameters:
builder- the optionalStringBuilderwhere data may have already been appended.acceptEot-trueto acceptEOT,falseotherwise.- Returns:
nullifacceptEotisfalse, otherwise theStringfrom the givenStringBuilderor the emptyStringin case theStringBuilderwasnull.
-
readUntil
Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the givenstopcharacter or the end is reached.
After the call of this method, the current index will point to the next character after the (first)stopcharacter or to the end if NO such character exists.- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
stop- is the character to read until.acceptEot- iftruethe end of data will be treated asstop, too.- Returns:
- the string with all read characters excluding the
stopcharacter ornullif there was nostopcharacter andacceptEndisfalse.
-
readUntil
Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the givenstopcharacter or the end of the string to parse is reached. In advance toCharStreamScanner.readUntil(char, boolean), this method will scan the input using the givensyntaxwhich e.g. allows toescapethe stop character.
After the call of this method, the current index will point to the next character after the (first)stopcharacter or to the end of the string if NO such character exists.- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
stop- is the character to read until.acceptEot- iftruethe end of data will be treated asstop, too.syntax- contains the characters specific for the syntax to read.- Returns:
- the string with all read characters excluding the
stopcharacter ornullif there was nostopcharacter. - See Also:
-
readUntil
Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the givenCharFilteracceptsthe current character as stop character or the end of data is reached. In advance toCharStreamScanner.readUntil(char, boolean), this method will scan the input using the givensyntaxwhich e.g. allows toescapethe stop character.
After the call of this method, the current index will point to the firstacceptedstop character or to the end of the string if NO such character exists.- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
filter- is used todecidewhere to stop.acceptEot- iftruethe end of data will be treated asstop, too.syntax- contains the characters specific for the syntax to read.- Returns:
- the string with all read characters excluding the
stopcharacter ornullif there was nostopcharacter. - See Also:
-
readUntil
Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the given (un-escaped)stopcharacter or the end is reached.
In advance toCharStreamScanner.readUntil(char, boolean), this method allows that thestopcharacter may be used in the input-string by adding the givenescapecharacter. After the call of this method, the current index will point to the next character after the (first)stopcharacter or to the end if NO such character exists.
This method is especially useful when quoted strings should be parsed. E.g.:CharStreamScannerscanner = getScanner(); doSomething(); char c = scanner.CharStreamScanner.next(); if ((c == '"') || (c == '\'')) { char escape = c; // may also be something like '\\' String quote = scanner.readUntil(c, false, escape) } else { doOtherThings(); }- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
stop- is the character to read until.acceptEot- iftruethe end of data will be treated asstop, too.escape- is the character used to escape thestopcharacter. To add an occurrence of theescapecharacter it has to be duplicated (occur twice). Theescapecharacter may also be equal to thestopcharacter. If other regular characters are escaped theescapecharacter is simply ignored.- Returns:
- the string with all read characters excluding the
stopcharacter ornullif there was nostopcharacter andacceptEndisfalse.
-
readUntil
Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the first characteracceptedby the givenfilteror the end is reached.
After the call of this method, the current index will point to the firstacceptedstop character or to the end if NO such character exists.- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
filter- is used todecidewhere to stop.acceptEot- iftrueif end of data should be treated like thestopcharacter and the rest of the text will be returned,falseotherwise (to returnnullif the end of data was reached and the scanner has been consumed).- Returns:
- the string with all read characters not
acceptedby the givenCharFilterornullif there was noacceptedcharacter andacceptEndisfalse.
-
readUntil
public String readUntil(CharFilter stopFilter, boolean acceptEot, String stop, boolean ignoreCase, boolean trim) Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the first characteracceptedby the givenfilter, the givenstopStringor the end is reached.
After the call of this method, the current index will point to the firstacceptedstop character, or to the first character of the givenstopStringor to the end if NO such character exists.- Specified by:
readUntilin interfaceCharStreamScanner- Parameters:
stopFilter- is used todecidewhere to stop.acceptEot- iftrueif the end of data should be treated like thestopcharacter and the rest of the text will be returned,falseotherwise (to returnnullif the end of data was reached and the scanner has been consumed).stop- theStringwhere to stop consuming data. Should be at least two characters long (otherwise accept byCharFilterinstead).ignoreCase- - iftruethe case of the characters is ignored when compared with characters fromstopString.trim- -trueif the result should betrimmed,falseotherwise.- Returns:
- the string with all read characters not
acceptedby the givenCharFilteror until the givenstopStringwas detected. If the end of data was reached without hittingstopthe entire rest of the data is returned ornullifacceptEndisfalse. Thre result will betrimmediftrimistrue.
-
verifyLookahead
protected void verifyLookahead(int length) - Parameters:
length- the number of characters for lookahead (match without consuming). May fail if thelengthexceeds the buffer size.
-
expectRestWithLookahead
protected abstract boolean expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip) - 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:
-
require
Description copied from interface:CharStreamScannerThis method verifies that theexpectedstring 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.
expectUnsafe(expected, ignoreCase)) { throw newIllegalStateException(...); }- Specified by:
requirein interfaceCharStreamScanner- Parameters:
expected- is the expected string.ignoreCase- - iftruethe case of the characters is ignored during comparison.
-
expectOne
public boolean expectOne(char expected, boolean warning) Description copied from interface:CharStreamScannerThis method checks if thenext characteris equal to the givenexpectedcharacter.
If the character matched with theexpectedcharacter, the parser points to the next character. Otherwise its position will remain unchanged.- Specified by:
expectOnein interfaceCharStreamScanner- Parameters:
expected- the character to expect asnextin this stream.warning-truetoadd a warningin case the expected character was not present,falseotherwise.- Returns:
trueif the expected character was found and consumer,falseotherwise (and this stream remains unchanged).
-
expectOne
Description copied from interface:CharStreamScannerThis method checks that thenext characterisacceptedby the givenCharFilter.
If the current character was as expected, the parser points to the next character. Otherwise its position will remain unchanged.- Specified by:
expectOnein interfaceCharStreamScanner- Parameters:
expected- is theCharFilteracceptingthe expected chars.- Returns:
trueif the current character isaccepted,falseotherwise.
-
expectUnsafe
Description copied from interface:CharStreamScannerThis method skips allnext charactersas long as they equal to the according character of theexpectedstring.
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 similar to the following code:
ATTENTION:read(expected.length).equals[IgnoreCase](expected)
In most cases you want to preferCharStreamScanner.expect(String, boolean)instead of using this method. SeeCharStreamScanner.expectUnsafe(String)for details.- Specified by:
expectUnsafein interfaceCharStreamScanner- Parameters:
expected- is the expected string.ignoreCase- - iftruethe case of the characters is ignored when compared.- Returns:
trueif theexpectedstring was successfully consumed from this scanner,falseotherwise.- See Also:
-
readLine
- Specified by:
readLinein interfaceCharStreamScanner- Parameters:
trim- -trueif the result should betrimmed,falseotherwise.- Returns:
- a
Stringwith the data until the end of the current line (trimmediftrimistrue) or the end of the data. Will benullif the end has already been reached andCharStreamScanner.hasNext()returnsfalse.
-
readJavaStringLiteral
Description copied from interface:CharStreamScannerReads and parses a JavaStringliteral value according to JLS 3.10.6.
As a complex example for the input "Hi \"\176\477\579•∑\"\n" this scanner would return theStringoutputHi "~'7/9•∑"followed by a newline character.- Specified by:
readJavaStringLiteralin interfaceCharStreamScanner- Parameters:
severity- theTextFormatMessageTypeto use to report invalid escape sequences or missing terminating quotation.- Returns:
- the parsed Java
Stringliteral value ornullif not pointing to aStringliteral.
-
readJavaCharLiteral
Description copied from interface:CharStreamScannerReads and parses a JavaCharacterliteral 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:
readJavaCharLiteralin interfaceCharStreamScanner- Parameters:
severity- theTextFormatMessageTypeto use to report invalid escape sequences or missing terminating quotation.- Returns:
- the parsed Java
Characterliteral value ornullif not pointing to aCharacterliteral.
-
readJavaNumberLiteral
Description copied from interface:CharStreamScannerReads a JavaNumberliteral (e.g. "1L" or "1.3F").- Specified by:
readJavaNumberLiteralin interfaceCharStreamScanner- Returns:
- the consumed
Numberornullif no number literal was found and thepositionremains unchainged.
-
read
Description copied from interface:CharStreamScannerThis method reads the number ofnext charactersgiven bycountand returns them as string. If there are less charactersavailablethe returned string will be shorter thancountand only contain the available characters.- Specified by:
readin interfaceCharStreamScanner- Parameters:
count- is the number of characters to read. You may useInteger.MAX_VALUEto 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 isavailableat all.
-
read
Description copied from interface:CharStreamScannerThis method reads the number ofnext charactersgiven bycountandappendsthem to the givenStringBuilder. If there are less charactersavailablethen only the remaining characters will be appended resulting in less characters thancount.- Specified by:
readin interfaceCharStreamScanner- Parameters:
count- is the number of characters to read. You may useInteger.MAX_VALUEto read until the end of data if the data-size is suitable.builder- theStringBuilderwhere toappendthe characters to read.
-
readDigit
public int readDigit(int radix) Description copied from interface:CharStreamScannerThis method reads thenext characterif it is a digit within the givenradix. Else the state remains unchanged.- Specified by:
readDigitin interfaceCharStreamScanner- Parameters:
radix- the radix that defines the range of the digits. SeeInteger.parseInt(String, int). E.g.10to read any Latin digit (seeCharStreamScanner.readDigit()),8to read octal digit,16to read hex decimal digits.- Returns:
- the numeric value of the next digit within the given
radixor-1if thenext characteris no such digit.
-
readNumber
Description copied from interface:CharStreamScannerGeneric way to read and parse any kind ofNumber.- Specified by:
readNumberin interfaceCharStreamScanner- Parameters:
numberParser- theCharScannerNumberParser. Can decide if sign, digits, radix, exponent, or even specials are
-
readDouble
Description copied from interface:CharStreamScannerThis method reads the double value (decimal number) starting at the current position by reading as many matching characters as available and returns itsparsedvalue.- Specified by:
readDoublein interfaceCharStreamScanner- Parameters:
radixMode- theCharScannerRadixHandler- e.g.CharScannerRadixMode.ALL.- Returns:
- the parsed
doublenumber ornullif the current current position does not point to a number.
-
readFloat
Description copied from interface:CharStreamScannerThis method reads aFloatvalue from the current positionconsumingas many matching characters as available.- Specified by:
readFloatin interfaceCharStreamScanner- Parameters:
radixMode- theCharScannerRadixHandler- e.g.CharScannerRadixMode.ALL.- Returns:
- the parsed
Floatvalue ornullif the current current position does not point to aFloatnumber.
-
readLong
- Specified by:
readLongin interfaceCharStreamScanner- Parameters:
radixMode- theCharScannerRadixHandler- e.g.CharScannerRadixMode.ALL.- Returns:
- the consumed
Longvalue ornullif no such value was present and thepositionremains unchanged.
-
readInteger
- Specified by:
readIntegerin interfaceCharStreamScanner- Parameters:
radixMode- theCharScannerRadixHandler- e.g.CharScannerRadixMode.ALL.- Returns:
- the consumed
Integervalue ornullif no such value was present and thepositionremains unchanged. - Throws:
NumberFormatException- if the current current position does not point to aLongvalue.
-
readUnsignedLong
Description copied from interface:CharStreamScannerThis method reads the long starting at the current position by reading as many Latin digits as available but at maximum the givenmaxDigitsand returns itsparsedvalue.
ATTENTION:
This method does NOT treat signs (+or-) to do so, scan them yourself before and negate the result as needed.- Specified by:
readUnsignedLongin interfaceCharStreamScanner- Parameters:
maxDigits- is the maximum number of digits that will be read. The value has to be positive (greater than zero). Should not be greater than19as this will exceed the range oflong.- Returns:
- the parsed number.
- Throws:
NumberFormatException- if the number at the current position could not be parsed.
-
skip
public int skip(int count) Description copied from interface:CharStreamScannerThis method skips the number ofnext charactersgiven bycount.- Specified by:
skipin interfaceCharStreamScanner- Parameters:
count- is the number of characters to skip. You may useInteger.MAX_VALUEto 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 the end of data was reached.
-
skipNewLine
public int skipNewLine()- Specified by:
skipNewLinein interfaceCharStreamScanner- Returns:
0if thenext characeteris not a newline and the stream remains unchanged,1if thenext characeterwas '\n' and has beenskipped, or2if thenext characetershave been '\r' and '\n' and have beenskipped.
-
skipUntil
public boolean skipUntil(char stop) Description copied from interface:CharStreamScannerThis method skips allnext charactersuntil the givenstopcharacter or the end is reached. If thestopcharacter was reached, this scanner will point to the next character afterstopwhen this method returns.- Specified by:
skipUntilin interfaceCharStreamScanner- Parameters:
stop- is the character to read until.- Returns:
trueif the first occurrence of the givenstopcharacter has been passed,falseif there is no such character.
-
skipUntil
public boolean skipUntil(char stop, char escape) Description copied from interface:CharStreamScannerThis method reads allnext charactersuntil the givenstopcharacter or the end of the string to parse is reached. In advance toCharStreamScanner.skipUntil(char), this method will read over thestopcharacter if it is escaped with the givenescapecharacter.- Specified by:
skipUntilin interfaceCharStreamScanner- Parameters:
stop- is the character to read until.escape- is the character used to escape the stop character (e.g. '\').- Returns:
trueif the first occurrence of the givenstopcharacter has been passed,falseif there is no such character.
-
skipWhile
public int skipWhile(char c) Description copied from interface:CharStreamScannerThis method reads allnext charactersthat 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 charactercor to the end if NO such character exists.- Specified by:
skipWhilein interfaceCharStreamScanner- Parameters:
c- is the character to read over.- Returns:
- the number of characters that have been skipped.
-
skipWhile
Description copied from interface:CharStreamScannerThis method reads allnext charactersthat areacceptedby the givenfilter.
After the call of this method, the current index will point to the next character that was NOTacceptedby the givenfilter. If the nextmaxcharacters or the characters left until theendof this scanner areaccepted, only that amount of characters are skipped.- Specified by:
skipWhilein interfaceCharStreamScanner- Parameters:
filter- is used todecidewhich characters should be accepted.max- is the maximum number of characters that may be skipped.- Returns:
- the number of skipped characters.
- See Also:
-
skipOver
Description copied from interface:CharStreamScannerThis method consumes allnext charactersuntil the givensubstringhas been detected, a character wasacceptedby the givenCharFilteror the end of data 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 to end of data.- Specified by:
skipOverin interfaceCharStreamScanner- Parameters:
substring- is the substring to search and skip over starting at the current index.ignoreCase- - iftruethe case of the characters is ignored when compared with characters fromsubstring.stopFilter- is the filter used todetectstop characters. If such character was detected, the skip is stopped and the parser points to the character after the stop character. Thesubstringshould NOT contain astop character.- Returns:
trueif the givensubstringoccurred and has been passed andfalseif a stop character has been detected or the end of the string has been reached without any occurrence of the givensubstringor stop character.
-
readWhile
Description copied from interface:CharStreamScannerThis method reads allnext charactersthat areacceptedby the givenfilter.
After the call of this method, the current index will point to the next character that was NOTacceptedby the givenfilter. If the nextmaxcharacters or the characters left until theendof this scanner areaccepted, only that amount of characters are skipped.- Specified by:
readWhilein interfaceCharStreamScanner- Parameters:
filter- used todecidewhich characters should be accepted.min- the minimum number of characters expected.max- the maximum number of characters that should be read.- Returns:
- a string with all characters
acceptedby the givenfilterlimited to the length ofmaxand theendof this scanner. Will be the empty string if no character was accepted. - See Also:
-
requireMin
- Parameters:
actual- the actual number of characters.min- the minimum number of characters required.filter- theCharFilterthat was used.
-
getBufferParsed
- Specified by:
getBufferParsedin interfaceCharStreamScanner- Returns:
- the
Stringwith the characters that have already been parsed but are still available in the underlying buffer. May be used for debugging or error messages.
-
getBufferToParse
- Specified by:
getBufferToParsein interfaceCharStreamScanner- Returns:
- the
Stringwith the characters that have not yet been parsed but are available in the underlying buffer. May be used for debugging or error messages.
-
toString
-