public final class StringParser
extends java.lang.Object
findXxxx()
and
skipXxxx()
families of methods to remember significant
offsets. To retrieve the parsed substrings, call the extract()
method with the appropriate saved offset values.Constructor and Description |
---|
StringParser()
Construct a string parser with no preset string to be parsed.
|
StringParser(java.lang.String string)
Construct a string parser that is initialized to parse the specified
string.
|
Modifier and Type | Method and Description |
---|---|
void |
advance()
Advance the current parsing position by one, if we are not already
past the end of the string.
|
java.lang.String |
extract(int start)
Extract and return a substring that starts at the specified position,
and extends to the end of the string being parsed.
|
java.lang.String |
extract(int start,
int end)
Extract and return a substring that starts at the specified position,
and ends at the character before the specified position.
|
int |
findChar(char ch)
Return the index of the next occurrence of the specified character,
or the index of the character after the last position of the string
if no more occurrences of this character are found.
|
int |
findText()
Return the index of the next occurrence of a non-whitespace character,
or the index of the character after the last position of the string
if no more non-whitespace characters are found.
|
int |
findWhite()
Return the index of the next occurrence of a whitespace character,
or the index of the character after the last position of the string
if no more whitespace characters are found.
|
int |
getIndex()
Return the zero-relative index of our current parsing position
within the string being parsed.
|
int |
getLength()
Return the length of the string we are parsing.
|
java.lang.String |
getString()
Return the String we are currently parsing.
|
protected boolean |
isWhite(char ch)
Is the specified character considered to be whitespace?
|
void |
reset()
Reset the current state of the parser to the beginning of the
current string being parsed.
|
void |
setString(java.lang.String string)
Set the String we are currently parsing.
|
int |
skipChar(char ch)
Advance the current parsing position while it is pointing at the
specified character, or until it moves past the end of the string.
|
int |
skipText()
Advance the current parsing position while it is pointing at a
non-whitespace character, or until it moves past the end of the string.
|
int |
skipWhite()
Advance the current parsing position while it is pointing at a
whitespace character, or until it moves past the end of the string.
|
public StringParser()
public StringParser(java.lang.String string)
string
- The string to be parsedpublic int getIndex()
public int getLength()
public java.lang.String getString()
public void setString(java.lang.String string)
string
- The string to be parsed.public void advance()
public java.lang.String extract(int start)
start
- Starting index, zero relative, inclusivepublic java.lang.String extract(int start, int end)
start
- Starting index, zero relative, inclusiveend
- Ending index, zero relative, exclusivepublic int findChar(char ch)
ch
- Character to be foundpublic int findText()
public int findWhite()
public void reset()
public int skipChar(char ch)
ch
- Character to be skippedpublic int skipText()
public int skipWhite()
protected boolean isWhite(char ch)
ch
- Character to be checkedCopyright © 2000-2015 Apache Software Foundation. All Rights Reserved.