org.freecompany.util.text
Class Tokenizer

java.lang.Object
  extended by org.freecompany.util.text.Scanner
      extended by org.freecompany.util.text.Tokenizer

public class Tokenizer
extends Scanner

Provides methods to tokenize character sequence given either absolute indexes or sequence for which to scan. TODO: Make the whitespace boolean a ctor argument and refactor out a trim method.


Constructor Summary
Tokenizer()
           
 
Method Summary
static java.lang.CharSequence after(java.lang.CharSequence target, java.lang.CharSequence sequence)
          Retrieves the remaining characters after the provided sequence.
static java.lang.CharSequence after(java.lang.CharSequence target, java.lang.CharSequence sequence, boolean trim)
          Retrieves the remaining characters after the provided sequence, optionally trimming the results.
static java.lang.CharSequence after(java.lang.CharSequence target, int index)
          Retrieves the remaining characters after the provided index.
static java.lang.CharSequence after(java.lang.CharSequence target, int start, boolean trim)
          Retrieves the remaining characters after the provided index, optionally trimming the results.
static java.lang.CharSequence after(TokenizerState state, java.lang.CharSequence sequence)
          Retrieves the remaining characters after the provided sequence, starting at the current position.
static java.lang.CharSequence before(java.lang.CharSequence target, java.lang.CharSequence sequence)
          Retrieves the characters preceeding the provided sequence.
static java.lang.CharSequence before(java.lang.CharSequence target, java.lang.CharSequence sequence, boolean trim)
          Retrieves the characters preceeding the provided sequence, optionally trimming the resulting sequence.
static java.lang.CharSequence before(java.lang.CharSequence target, int start)
          Convenience method for returning the untrimmed portion of a sequence up to the provided index.
static java.lang.CharSequence before(java.lang.CharSequence target, int start, boolean trim)
          Retrieves the characters preceding the provided index, optionally trimming the results.
static java.lang.CharSequence before(TokenizerState state, java.lang.CharSequence sequence)
          Retrieves the characters preceeding the provided sequence, starting at the current position.
static java.lang.CharSequence between(java.lang.CharSequence target, java.lang.CharSequence one, java.lang.CharSequence two)
          Retrieves the next token that falls between the two provided sequences.
static java.lang.CharSequence between(java.lang.CharSequence target, java.lang.CharSequence one, java.lang.CharSequence two, boolean trim)
          Retrieves the next token that falls between the two provided sequences, optionally trimming the results.
static java.lang.CharSequence between(TokenizerState state, java.lang.CharSequence one, java.lang.CharSequence two)
          Retrieves the next token that falls between the two provided sequences, starting at the current position.
static java.lang.CharSequence rest(TokenizerState state)
          Retrieves the remaining characters from this tokenizer.
protected static java.lang.CharSequence sub(java.lang.CharSequence target, int start, int end, boolean trim)
           
 
Methods inherited from class org.freecompany.util.text.Scanner
end, endsWith, last, match, match, scan, scan, scan, scan, skip, skip, skip, startsWith
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tokenizer

public Tokenizer()
Method Detail

sub

protected static final java.lang.CharSequence sub(java.lang.CharSequence target,
                                                  int start,
                                                  int end,
                                                  boolean trim)

before

public static final java.lang.CharSequence before(TokenizerState state,
                                                  java.lang.CharSequence sequence)
Retrieves the characters preceeding the provided sequence, starting at the current position. The position is reset to the character following the match only if the match is found.

Returns:
the characters preceeding the sequence, or null if the sequence is not found. Retrieves the next token delimited by the provided sequence.

after

public static final java.lang.CharSequence after(TokenizerState state,
                                                 java.lang.CharSequence sequence)
Retrieves the remaining characters after the provided sequence, starting at the current position. The position is moved to the end of the target only if a match is found.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

between

public static final java.lang.CharSequence between(TokenizerState state,
                                                   java.lang.CharSequence one,
                                                   java.lang.CharSequence two)
Retrieves the next token that falls between the two provided sequences, starting at the current position. The position is moved to the character following the match only if the match is found.

Returns:
the characters between the two sequences, or null if either sequence is not found.

rest

public static final java.lang.CharSequence rest(TokenizerState state)
Retrieves the remaining characters from this tokenizer.


before

public static final java.lang.CharSequence before(java.lang.CharSequence target,
                                                  java.lang.CharSequence sequence)
Retrieves the characters preceeding the provided sequence.

Returns:
the characters preceeding the sequence, or null if the sequence is not found.

before

public static final java.lang.CharSequence before(java.lang.CharSequence target,
                                                  java.lang.CharSequence sequence,
                                                  boolean trim)
Retrieves the characters preceeding the provided sequence, optionally trimming the resulting sequence.

Returns:
the characters preceeding the sequence, or null if the sequence is not found.

before

public static final java.lang.CharSequence before(java.lang.CharSequence target,
                                                  int start)
Convenience method for returning the untrimmed portion of a sequence up to the provided index. Equivalent to calling before with false as the last parameter.


before

public static final java.lang.CharSequence before(java.lang.CharSequence target,
                                                  int start,
                                                  boolean trim)
Retrieves the characters preceding the provided index, optionally trimming the results.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

after

public static final java.lang.CharSequence after(java.lang.CharSequence target,
                                                 java.lang.CharSequence sequence)
Retrieves the remaining characters after the provided sequence.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

after

public static final java.lang.CharSequence after(java.lang.CharSequence target,
                                                 int index)
Retrieves the remaining characters after the provided index.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

after

public static final java.lang.CharSequence after(java.lang.CharSequence target,
                                                 java.lang.CharSequence sequence,
                                                 boolean trim)
Retrieves the remaining characters after the provided sequence, optionally trimming the results.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

after

public static final java.lang.CharSequence after(java.lang.CharSequence target,
                                                 int start,
                                                 boolean trim)
Retrieves the remaining characters after the provided index, optionally trimming the results.

Returns:
the characters remaining after the sequence, or null if the sequence is not found.

between

public static final java.lang.CharSequence between(java.lang.CharSequence target,
                                                   java.lang.CharSequence one,
                                                   java.lang.CharSequence two)
Retrieves the next token that falls between the two provided sequences.

Returns:
the characters between the two sequences, or null if either sequence is not found.

between

public static final java.lang.CharSequence between(java.lang.CharSequence target,
                                                   java.lang.CharSequence one,
                                                   java.lang.CharSequence two,
                                                   boolean trim)
Retrieves the next token that falls between the two provided sequences, optionally trimming the results.

Returns:
the characters between the two sequences, or null if either sequence is not found.