public class

TokenQueue

extends Object
java.lang.Object
   ↳ org.jsoup.parser.TokenQueue

Class Overview

A character queue with parsing helpers.

Summary

Public Constructors
TokenQueue(String data)
Create a new TokenQueue.
Public Methods
void addFirst(String seq)
Add a string to the start of the queue.
void addFirst(Character c)
Add a character to the start of the queue (will be the next character retrieved).
void advance()
Drops the next character off the queue.
String chompBalanced(char open, char close)
Pulls a balanced string off the queue.
String chompTo(String seq)
Pulls a string off the queue (like consumeTo), and then pulls off the matched string (but does not return it).
String chompToIgnoreCase(String seq)
void consume(String seq)
Consumes the supplied sequence of the queue.
char consume()
Consume one character off queue.
String consumeAttributeKey()
Consume an attribute key off the queue (letter, digit, -, _, :")
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
String consumeElementSelector()
Consume a CSS element selector (tag name, but | instead of : for namespaces, to not conflict with :pseudo selects).
String consumeTagName()
Consume an tag name off the queue (word or :, _, -)
String consumeTo(String seq)
Pulls a string off the queue, up to but exclusive of the match sequence, or to the queue running out.
String consumeToAny(String... seq)
Consumes to the first sequence provided, or to the end of the queue.
String consumeToIgnoreCase(String seq)
boolean consumeWhitespace()
Pulls the next run of whitespace characters of the queue.
String consumeWord()
Retrieves the next run of word type (letter or digit) off the queue.
boolean isEmpty()
Is the queue empty?
boolean matchChomp(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(String seq)
Tests if the next characters on the queue match the sequence.
boolean matchesAny(String... seq)
Tests if the next characters match any of the sequences.
boolean matchesAny(char... seq)
boolean matchesCS(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.
String remainder()
Consume and return whatever is left on the queue.
String toString()
static String unescape(String in)
Unescaped a \ escaped string.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public TokenQueue (String data)

Create a new TokenQueue.

Parameters
data string of data to back queue.

Public Methods

public void addFirst (String seq)

Add a string to the start of the queue.

Parameters
seq string to add.

public void addFirst (Character c)

Add a character to the start of the queue (will be the next character retrieved).

Parameters
c character to add

public void advance ()

Drops the next character off the queue.

public String chompBalanced (char open, char close)

Pulls a balanced string off the queue. E.g. if queue is "(one (two) three) four", (,) will return "one (two) three", and leave " four" on the queue. Unbalanced openers and closers can be escaped (with \). Those escapes will be left in the returned string, which is suitable for regexes (where we need to preserve the escape), but unsuitable for contains text strings; use unescape for that.

Parameters
open opener
close closer
Returns
  • data matched from the queue

public String chompTo (String seq)

Pulls a string off the queue (like consumeTo), and then pulls off the matched string (but does not return it).

If the queue runs out of characters before finding the seq, will return as much as it can (and queue will go isEmpty() == true).

Parameters
seq String to match up to, and not include in return, and to pull off queue. Case sensitive.
Returns
  • Data matched from queue.

public String chompToIgnoreCase (String seq)

public void consume (String seq)

Consumes the supplied sequence of the queue. If the queue does not start with the supplied sequence, will throw an illegal state exception -- but you should be running match() against that condition.

Case insensitive.

Parameters
seq sequence to remove from head of queue.

public char consume ()

Consume one character off queue.

Returns
  • first character on queue.

public String consumeAttributeKey ()

Consume an attribute key off the queue (letter, digit, -, _, :")

Returns
  • attribute key

public 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

Returns
  • identifier

public String consumeElementSelector ()

Consume a CSS element selector (tag name, but | instead of : for namespaces, to not conflict with :pseudo selects).

Returns
  • tag name

public String consumeTagName ()

Consume an tag name off the queue (word or :, _, -)

Returns
  • tag name

public String consumeTo (String seq)

Pulls a string off the queue, up to but exclusive of the match sequence, or to the queue running out.

Parameters
seq String to end on (and not include in return, but leave on queue). Case sensitive.
Returns
  • The matched data consumed from queue.

public String consumeToAny (String... seq)

Consumes to the first sequence provided, or to the end of the queue. Leaves the terminator on the queue.

Parameters
seq any number of terminators to consume to. Case insensitive.
Returns
  • consumed string

public String consumeToIgnoreCase (String seq)

public boolean consumeWhitespace ()

Pulls the next run of whitespace characters of the queue.

public String consumeWord ()

Retrieves the next run of word type (letter or digit) off the queue.

Returns
  • String of word characters from queue, or empty string if none.

public boolean isEmpty ()

Is the queue empty?

Returns
  • true if no data left in queue.

public boolean matchChomp (String seq)

Tests if the queue matches the sequence (as with match), and if they do, removes the matched string from the queue.

Parameters
seq String to search for, and if found, remove from queue.
Returns
  • true if found and removed, false if not found.

public boolean matches (String seq)

Tests if the next characters on the queue match the sequence. Case insensitive.

Parameters
seq String to check queue for.
Returns
  • true if the next characters match.

public boolean matchesAny (String... seq)

Tests if the next characters match any of the sequences. Case insensitive.

public boolean matchesAny (char... seq)

public boolean matchesCS (String seq)

Case sensitive match test.

public boolean matchesStartTag ()

public boolean matchesWhitespace ()

Tests if queue starts with a whitespace character.

Returns
  • if starts with whitespace

public boolean matchesWord ()

Test if the queue matches a word character (letter or digit).

Returns
  • if matches a word character

public char peek ()

Retrieves but does not remove the first character from the queue.

Returns
  • First character, or 0 if empty.

public String remainder ()

Consume and return whatever is left on the queue.

Returns
  • remained of queue.

public String toString ()

public static String unescape (String in)

Unescaped a \ escaped string.

Parameters
in backslash escaped string
Returns
  • unescaped string