public class StringChunker
extends java.lang.Object
find()
methods, parsing found "chunks" one at a time.
Interally, there is a text buffer and a pointer to a position in that buffer;
the pointer moves as find()
executes.Constructor and Description |
---|
StringChunker()
Creates an uninitialized StringChunker.
|
StringChunker(java.lang.String text)
Creates a StringChunker ready to use.
|
Modifier and Type | Method and Description |
---|---|
boolean |
find(java.util.regex.Pattern regex)
Does the same as
find(String) , but using a regular expression. |
boolean |
find(java.lang.String lookFor)
Finds the given substring, starting at the current index, and sets
the internal index to the location directly following the text found.
|
boolean |
findOrFinish(java.util.regex.Pattern regex)
Does the same as
findOrFinish(String) , but using a regular expression. |
boolean |
findOrFinish(java.lang.String lookFor)
Makes it easier to deal with end-of-String vs.
|
boolean |
finished() |
int |
foundAt() |
java.lang.String |
getEverythingSoFar()
Provides all the text up to the current position of the internal pointer; i.e.
|
java.lang.String |
getFound()
Obtains the text that was found by
find() . |
java.lang.String |
getIncluding()
Combines the results of
getUpTo() . |
java.lang.String |
getIncluding(java.lang.String lookFor)
Combines find() and getIncluding().
|
int |
getIndex() |
java.lang.String |
getRest()
Moves index to end of buffer and retrieves rest of text.
|
java.lang.String |
getText() |
java.lang.String |
getUpTo()
Obtains the text before the text found by
find() . |
java.lang.String |
getUpTo(java.lang.String lookFor)
Combines find() and getUpTo().
|
java.lang.String |
getUpToOrGetRest()
If last find() failed, invokes getRest(), else getUpTo().
|
java.lang.String |
getUpToOrGetRest(java.lang.String val)
Combines find() with getUpToOrGetRest().
|
static void |
main(java.lang.String[] args)
Call with two args: 1) A string to search 2) A regex to search with.
|
void |
move(int distance)
Moves the internal buffer index forward the specified distance.
|
StringChunker |
reset()
Sets the internal index back to 0, as if find()
had never been invoked.
|
StringChunker |
reset(java.lang.String text)
Completely reinitializes this StringChunker.
|
void |
setIndex(int index)
Sets the internal buffer index to a specific position.
|
public StringChunker(java.lang.String text)
text
- The String to be parsed.public StringChunker()
reset(String)
to
initialize it.public StringChunker reset()
public StringChunker reset(java.lang.String text)
public java.lang.String getText()
public int getIndex()
public int foundAt()
public boolean finished()
public void move(int distance)
public void setIndex(int index)
public boolean find(java.lang.String lookFor)
public boolean findOrFinish(java.lang.String lookFor)
public boolean find(java.util.regex.Pattern regex)
find(String)
, but using a regular expression.public boolean findOrFinish(java.util.regex.Pattern regex)
findOrFinish(String)
, but using a regular expression.public java.lang.String getUpTo()
find()
.public java.lang.String getFound()
find()
.public java.lang.String getIncluding()
getUpTo()
. and getFound()
.public java.lang.String getEverythingSoFar()
public java.lang.String getUpTo(java.lang.String lookFor)
public java.lang.String getIncluding(java.lang.String lookFor)
public java.lang.String getRest()
public java.lang.String getUpToOrGetRest()
public java.lang.String getUpToOrGetRest(java.lang.String val)
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception