Class StringParser
java.lang.Object
com.northconcepts.datapipeline.core.StringParser
- All Implemented Interfaces:
IParser
An
IParser over an in-memory string.-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidconsume()voidconsume(int count) voidvoidconsumeWhitespace(char[] exception) Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.voidconsumeWhitespace(int exception) Skips spaces and tabs at the current position, stopping early at the given character.voidconsumeWhitespace(CharSequence exception) Skips whitespace at the current position, stopping where the given string (such as a field separator) begins.Wraps the exception in aDataExceptionand adds the parser's buffer and position as properties.longReturns the number of characters consumed so far (within the current line forLineParser).voidmatch(char expectedChar) Consumes the next character, throwing aDataExceptionif it is not the expected one.voidmatch(char[] expectedString) Consumes the expected string, throwing aDataExceptionat the first character that differs.voidConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs.voidConsumes the next character, throwing aDataExceptionprefixed withfailureMessageif it is not the expected one.voidmatch(CharSequence expectedString) Consumes the expected string, throwing aDataExceptionat the first character that differs.voidmatch(CharSequence expectedString, String failureMessage) Consumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs.matchUntil(char terminatingChar) Consumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionif the input ends first.matchUntil(char terminatingChar, String failureMessage) Consumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionprefixed withfailureMessageif the input ends first.Consumes and returns all remaining characters (of the current line forLineParser).intpeek(int index) Returns the character at the given 0-based offset ahead without consuming it, orIParser.EOFpast the end of the input.peekSequence(int offset, int length) Returns up tolengthcharacters starting at the given lookahead offset without consuming them; fewer if the input ends first.booleanpeekString(char[] lookahead) Indicates if the upcoming characters match the given string, without consuming them.booleanpeekString(CharSequence lookahead) Indicates if the upcoming characters match the given string, without consuming them.intpeekStringArray(char[][] lookahead) Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.intpeekStringArray(char[][] lookahead, int offset) Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.intpeekStringArray(CharSequence... lookahead) Returns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.intpeekStringArray(CharSequence[] lookahead, int offset) Returns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.booleanpeekStringOffset(char[] lookahead, int offset) Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.booleanpeekStringOffset(CharSequence lookahead, int offset) Indicates if the characters starting at the given lookahead offset match the given string, without consuming them.intpeekWhitespaceLength(int index) Returns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.intpop()Consumes and returns the next character, orIParser.EOFat the end of the input.booleanready()
-
Constructor Details
-
StringParser
-
-
Method Details
-
exception
Description copied from interface:IParserWraps the exception in aDataExceptionand adds the parser's buffer and position as properties. -
ready
- Specified by:
readyin interfaceIParser- Throws:
IOException
-
getColumn
public long getColumn()Description copied from interface:IParserReturns the number of characters consumed so far (within the current line forLineParser). -
peek
public int peek(int index) Description copied from interface:IParserReturns the character at the given 0-based offset ahead without consuming it, orIParser.EOFpast the end of the input. -
peekSequence
Description copied from interface:IParserReturns up tolengthcharacters starting at the given lookahead offset without consuming them; fewer if the input ends first.- Specified by:
peekSequencein interfaceIParser
-
peekString
Description copied from interface:IParserIndicates if the upcoming characters match the given string, without consuming them.- Specified by:
peekStringin interfaceIParser
-
peekStringOffset
Description copied from interface:IParserIndicates if the characters starting at the given lookahead offset match the given string, without consuming them.- Specified by:
peekStringOffsetin interfaceIParser
-
peekStringArray
Description copied from interface:IParserReturns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.- Specified by:
peekStringArrayin interfaceIParser
-
peekStringArray
Description copied from interface:IParserReturns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.- Specified by:
peekStringArrayin interfaceIParser
-
pop
public int pop()Description copied from interface:IParserConsumes and returns the next character, orIParser.EOFat the end of the input. -
match
Description copied from interface:IParserConsumes the next character, throwing aDataExceptionprefixed withfailureMessageif it is not the expected one. -
match
public void match(char expectedChar) Description copied from interface:IParserConsumes the next character, throwing aDataExceptionif it is not the expected one. -
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs. -
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionat the first character that differs. -
matchUntil
Description copied from interface:IParserConsumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionif the input ends first.- Specified by:
matchUntilin interfaceIParser
-
matchUntil
Description copied from interface:IParserConsumes and returns the text before the terminating character, then consumes the terminator; throws aDataExceptionprefixed withfailureMessageif the input ends first.- Specified by:
matchUntilin interfaceIParser
-
matchUntilEof
Description copied from interface:IParserConsumes and returns all remaining characters (of the current line forLineParser).- Specified by:
matchUntilEofin interfaceIParser
-
consume
public void consume() -
consume
public void consume(int count) -
consumeWhitespace
public void consumeWhitespace()- Specified by:
consumeWhitespacein interfaceIParser
-
consumeWhitespace
public void consumeWhitespace(int exception) Description copied from interface:IParserSkips spaces and tabs at the current position, stopping early at the given character.- Specified by:
consumeWhitespacein interfaceIParser
-
consumeWhitespace
Description copied from interface:IParserSkips whitespace at the current position, stopping where the given string (such as a field separator) begins.- Specified by:
consumeWhitespacein interfaceIParser
-
close
public void close() -
peekString
public boolean peekString(char[] lookahead) Description copied from interface:IParserIndicates if the upcoming characters match the given string, without consuming them.- Specified by:
peekStringin interfaceIParser
-
peekStringOffset
public boolean peekStringOffset(char[] lookahead, int offset) Description copied from interface:IParserIndicates if the characters starting at the given lookahead offset match the given string, without consuming them.- Specified by:
peekStringOffsetin interfaceIParser
-
peekStringArray
public int peekStringArray(char[][] lookahead) Description copied from interface:IParserReturns the index of the first string that matches the upcoming characters or -1 if none do, without consuming them.- Specified by:
peekStringArrayin interfaceIParser
-
match
Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionprefixed withfailureMessageat the first character that differs. -
match
public void match(char[] expectedString) Description copied from interface:IParserConsumes the expected string, throwing aDataExceptionat the first character that differs. -
consumeWhitespace
public void consumeWhitespace(char[] exception) Description copied from interface:IParserSkips whitespace at the current position, stopping where the given string (such as a field separator) begins.- Specified by:
consumeWhitespacein interfaceIParser
-
peekStringArray
public int peekStringArray(char[][] lookahead, int offset) Description copied from interface:IParserReturns the index of the first string that matches the characters at the given lookahead offset or -1 if none do.- Specified by:
peekStringArrayin interfaceIParser
-
peekWhitespaceLength
public int peekWhitespaceLength(int index) Description copied from interface:IParserReturns the number of consecutive whitespace characters starting at the given 0-based lookahead offset.- Specified by:
peekWhitespaceLengthin interfaceIParser
-