|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.string.ParseContext
public class ParseContext
Utility class supporting parsing of strings.
Instances of this class are not thread safe.
| Constructor Summary | |
|---|---|
ParseContext(String input)
Constructor. |
|
| Method Summary | |
|---|---|
IllegalArgumentException |
buildException()
Create a generic exception for rejecting the current input. |
IllegalArgumentException |
buildException(String message)
Create an exception for rejecting the current input. |
ParseContext |
clone()
Clone this instance. |
void |
expect(char ch)
Read and advance past the next character, which must match ch. |
int |
getIndex()
Get the current index into the original input string. |
String |
getInput()
Get the current input. |
String |
getOriginalInput()
Get the original input string as passed to the constructor. |
boolean |
isEOF()
Determine if we are at the end of the input. |
Matcher |
matchPrefix(Pattern regex)
Match the current input against the given regular expression and advance past it. |
Matcher |
matchPrefix(String regex)
Match the current input against the given regular expression and advance past it. |
char |
peek()
Read, but do not advance past, the next character. |
char |
read()
Read and advance past the next character. |
void |
reset()
Reset this instance. |
void |
setIndex(int index)
Set the current index into the original input string. |
void |
skipWhitespace()
Skip leading whitespace, if any. |
boolean |
tryLiteral(String prefix)
Determine if the current input starts with the given literal prefix. |
void |
unread()
Push back the previously read character. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ParseContext(String input)
input - the input string to parse| Method Detail |
|---|
public String getOriginalInput()
public String getInput()
public int getIndex()
setIndex(int)public void setIndex(int index)
index - new parse position
IllegalArgumentException - if index is greater than the original string lengthgetIndex()public void reset()
This method just invokes:
setIndex(0)
public Matcher matchPrefix(String regex)
regex - regular expression to match against the current input
IllegalArgumentException - if the current input does not matchpublic Matcher matchPrefix(Pattern regex)
regex - regular expression to match against the current input
IllegalArgumentException - if the current input does not matchpublic boolean tryLiteral(String prefix)
prefix - literal string to try to match against the current input
prefixpublic boolean isEOF()
public char read()
IllegalArgumentException - if there are no more characterspublic char peek()
IllegalArgumentException - if there are no more characterspublic void unread()
IllegalStateException - if the beginning of the original string has been reachedpublic void expect(char ch)
ch.
ch - the expected next character of input
IllegalArgumentException - if there are no more characters or the
next character read is not chpublic void skipWhitespace()
Character.isWhitespace(char)public ParseContext clone()
clone in class Objectpublic IllegalArgumentException buildException()
public IllegalArgumentException buildException(String message)
message - problem description, or null for none
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||