public class TokenQueue
extends java.lang.Object
Constructor and Description |
---|
TokenQueue(java.lang.String data)
Create a new TokenQueue.
|
Modifier and Type | Method and Description |
---|---|
void |
addFirst(java.lang.Character c)
Add a character to the start of the queue (will be the next character retrieved).
|
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 |
consumeAttributeKey()
Consume an attribute key off the queue (letter, digit, -, _, :")
|
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).
|
java.lang.String |
consumeTagName()
Consume an tag name off the queue (word or :, _, -)
|
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.
|
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.
|
boolean |
matchesCS(java.lang.String seq)
Case sensitive match test.
|
boolean |
matchesStartTag() |
boolean |
matchesWhitespace()
Tests if queue starts with a whitespace character.
|
boolean |
matchesWord()
Test if the queue matches a word character (letter or digit).
|
char |
peek()
Retrieves but does not remove the first character from the queue.
|
java.lang.String |
remainder()
Consume and return whatever is left on the queue.
|
java.lang.String |
toString() |
static java.lang.String |
unescape(java.lang.String in)
Unescape a \ escaped string.
|
public TokenQueue(java.lang.String data)
data
- string of data to back queue.public boolean isEmpty()
public char peek()
public void addFirst(java.lang.Character c)
c
- character to addpublic 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 matchesCS(java.lang.String seq)
seq
- string to case sensitively check forpublic boolean matchesAny(java.lang.String... seq)
seq
- list of strings to case insensitively check forpublic boolean matchesAny(char... seq)
public boolean matchesStartTag()
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 boolean consumeWhitespace()
public java.lang.String consumeWord()
public java.lang.String consumeTagName()
public java.lang.String consumeElementSelector()
public java.lang.String consumeCssIdentifier()
public java.lang.String consumeAttributeKey()
public java.lang.String remainder()
public java.lang.String toString()
toString
in class java.lang.Object