public class TokenQueue
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
CssIdentifierChars |
private static java.lang.String[] |
ElementSelectorChars |
private static char |
ESC |
private int |
pos |
private java.lang.String |
queue |
Constructor and Description |
---|
TokenQueue(java.lang.String data)
Create a new TokenQueue.
|
Modifier and Type | Method and Description |
---|---|
void |
addFirst(java.lang.String seq)
Add a string to the start of the queue.
|
void |
advance()
Drops the next character off the queue.
|
java.lang.String |
chompBalanced(char open,
char close)
Pulls a balanced string off the queue.
|
java.lang.String |
chompTo(java.lang.String seq)
Pulls a string off the queue (like consumeTo), and then pulls off the matched string (but does not return it).
|
java.lang.String |
chompToIgnoreCase(java.lang.String seq) |
char |
consume()
Consume one character off queue.
|
void |
consume(java.lang.String seq)
Consumes the supplied sequence of the queue.
|
java.lang.String |
consumeCssIdentifier()
Consume a CSS identifier (ID or class) off the queue (letter, digit, -, _)
http://www.w3.org/TR/CSS2/syndata.html#value-def-identifier
|
java.lang.String |
consumeElementSelector()
Consume a CSS element selector (tag name, but | instead of : for namespaces (or *| for wildcard namespace), to not conflict with :pseudo selects).
|
private java.lang.String |
consumeEscapedCssIdentifier(java.lang.String... matches) |
java.lang.String |
consumeTo(java.lang.String seq)
Pulls a string off the queue, up to but exclusive of the match sequence, or to the queue running out.
|
java.lang.String |
consumeToAny(java.lang.String... seq)
Consumes to the first sequence provided, or to the end of the queue.
|
java.lang.String |
consumeToIgnoreCase(java.lang.String seq) |
boolean |
consumeWhitespace()
Pulls the next run of whitespace characters of the queue.
|
java.lang.String |
consumeWord()
Retrieves the next run of word type (letter or digit) off the queue.
|
static java.lang.String |
escapeCssIdentifier(java.lang.String in) |
boolean |
isEmpty()
Is the queue empty?
|
boolean |
matchChomp(java.lang.String seq)
Tests if the queue matches the sequence (as with match), and if they do, removes the matched string from the
queue.
|
boolean |
matches(java.lang.String seq)
Tests if the next characters on the queue match the sequence.
|
boolean |
matchesAny(char... seq) |
boolean |
matchesAny(java.lang.String... seq)
Tests if the next characters match any of the sequences.
|
private boolean |
matchesCssIdentifier(java.lang.String... matches) |
boolean |
matchesWhitespace()
Tests if queue starts with a whitespace character.
|
boolean |
matchesWord()
Test if the queue matches a word character (letter or digit).
|
java.lang.String |
remainder()
Consume and return whatever is left on the queue.
|
private int |
remainingLength() |
java.lang.String |
toString() |
static java.lang.String |
unescape(java.lang.String in)
Unescape a \ escaped string.
|
private java.lang.String queue
private int pos
private static final char ESC
private static final java.lang.String[] ElementSelectorChars
private static final java.lang.String[] CssIdentifierChars
public TokenQueue(java.lang.String data)
data
- string of data to back queue.public boolean isEmpty()
private int remainingLength()
public void addFirst(java.lang.String seq)
seq
- string to add.public boolean matches(java.lang.String seq)
seq
- String to check queue for.public boolean matchesAny(java.lang.String... seq)
seq
- list of strings to case insensitively check forpublic boolean matchesAny(char... seq)
public boolean matchChomp(java.lang.String seq)
seq
- String to search for, and if found, remove from queue.public boolean matchesWhitespace()
public boolean matchesWord()
public void advance()
public char consume()
public void consume(java.lang.String seq)
Case insensitive.
seq
- sequence to remove from head of queue.public java.lang.String consumeTo(java.lang.String seq)
seq
- String to end on (and not include in return, but leave on queue). Case sensitive.public java.lang.String consumeToIgnoreCase(java.lang.String seq)
public java.lang.String consumeToAny(java.lang.String... seq)
seq
- any number of terminators to consume to. Case insensitive.public java.lang.String chompTo(java.lang.String seq)
If the queue runs out of characters before finding the seq, will return as much as it can (and queue will go isEmpty() == true).
seq
- String to match up to, and not include in return, and to pull off queue. Case sensitive.public java.lang.String chompToIgnoreCase(java.lang.String seq)
public java.lang.String chompBalanced(char open, char close)
open
- openerclose
- closerpublic static java.lang.String unescape(java.lang.String in)
in
- backslash escaped stringpublic static java.lang.String escapeCssIdentifier(java.lang.String in)
public boolean consumeWhitespace()
public java.lang.String consumeWord()
public java.lang.String consumeElementSelector()
public java.lang.String consumeCssIdentifier()
private java.lang.String consumeEscapedCssIdentifier(java.lang.String... matches)
private boolean matchesCssIdentifier(java.lang.String... matches)
public java.lang.String remainder()
public java.lang.String toString()
toString
in class java.lang.Object