com.stevesoft.pat
Class RegexTokenizer

java.lang.Object
  |
  +--com.stevesoft.pat.RegexTokenizer
All Implemented Interfaces:
java.util.Enumeration


public class RegexTokenizer
extends java.lang.Object
implements java.util.Enumeration

The RegexTokenizer is similar to the StringTokenizer class provided with java, but allows one to tokenize using regular expressions, rather than a simple list of characters. Tokens are any strings between the supplied regular expression, as well as any backreferences (things in parenthesis) contained within the regular expression.


Constructor Summary
RegexTokenizer(java.lang.String txt, Regex r)
          Initialize the tokenizer with a Regex object.
RegexTokenizer(java.lang.String txt, java.lang.String ptrn)
          Initialize the tokenizer with a string of text and a pattern

 
Method Summary
 java.lang.String[] allTokens()
          Returns all tokens in the String
 int countTokens()
          Determines the # of remaining tokens
 boolean hasMoreElements()
          Tells whether there are more tokens in the pattern.
 boolean hasMoreTokens()
          Tells whether there are more tokens in the pattern, but in the fashion of StringTokenizer.
 java.lang.Object nextElement()
          This should always be cast to a String, as in StringTokenizer, and as in StringTokenizer one can do this by calling nextString().
 java.lang.String nextToken()
          This is the equivalent (String)nextElement().
 java.lang.String nextToken(Regex nr)
          This asks for the next token, and changes the pattern being used at the same time.
 java.lang.String nextToken(java.lang.String newpat)
          This asks for the next token, and changes the pattern being used at the same time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexTokenizer

public RegexTokenizer(java.lang.String txt,
                      java.lang.String ptrn)
Initialize the tokenizer with a string of text and a pattern

RegexTokenizer


public RegexTokenizer(java.lang.String txt,
                      Regex r)
Initialize the tokenizer with a Regex object.
Method Detail

nextElement

public java.lang.Object nextElement()
This should always be cast to a String, as in StringTokenizer, and as in StringTokenizer one can do this by calling nextString().
Specified by:
nextElement in interface java.util.Enumeration

nextToken

public java.lang.String nextToken()
This is the equivalent (String)nextElement().

nextToken

public java.lang.String nextToken(java.lang.String newpat)
This asks for the next token, and changes the pattern being used at the same time.

nextToken

public java.lang.String nextToken(Regex nr)
This asks for the next token, and changes the pattern being used at the same time.

hasMoreElements

public boolean hasMoreElements()
Tells whether there are more tokens in the pattern.
Specified by:
hasMoreElements in interface java.util.Enumeration

hasMoreTokens

public boolean hasMoreTokens()
Tells whether there are more tokens in the pattern, but in the fashion of StringTokenizer.

countTokens

public int countTokens()
Determines the # of remaining tokens

allTokens

public java.lang.String[] allTokens()
Returns all tokens in the String