starwave.util.regexp
Class Regexp

java.lang.Object
  |
  +--starwave.util.regexp.Regexp

public class Regexp
extends java.lang.Object

A Regexp is a piece of a regular expression. The system is designed to be at once flexible and efficient. Therefore, very little allocation is done while matching a regexp. It's mostly all done during the compilation stage. Here's an example of how to use this class: import starwave.util.regexp.*; Regexp reg = Regexp.compile("^([a-z]*) ([0-9]*)"); String buffer = readFileIntoString("somefile.text"); Result result; int pos = 0; while ((result = reg.searchForward(buffer, pos)) != null) { System.out.println("Matched " + result.getMatch(1) + " and " + result.getMatch(2)); pos = result.matchEnd() + 1; }


Method Summary
static Regexp compile(java.lang.String expr)
           
static Regexp compile(java.lang.String expr, boolean mapCase)
          Return a compiled regular expression.
static void main(java.lang.String[] args)
           
 Result match(char[] data, int offset, int length)
          Returns true if the specified String is matched by this regular expression.
protected  boolean match(starwave.util.regexp.State state)
          Walks as far as it can down a regular expression, returning true if it made it all the way to the end, and false otherwise.
 Result match(java.lang.String data, int offset)
          Returns true if the specified String is matched by this regular expression.
 Result searchBackward(char[] data, int offset, int length)
          Returns true if the specified char array is matched from the specified offset backward by this regular expression.
 Result searchBackward(java.lang.String data, int offset)
          Returns true if the specified String is matched from the specified offset backward by this regular expression.
 Result searchForward(char[] data, int offset, int length)
          Returns true if the specified char array is matched anywhere by this regular expression.
 Result searchForward(java.lang.String data, int offset)
          Returns true if the specified String is matched anywhere by this regular expression.
 java.lang.String toString()
           
 java.lang.String toStringThis()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

compile

public static Regexp compile(java.lang.String expr)

compile

public static Regexp compile(java.lang.String expr,
                             boolean mapCase)
Return a compiled regular expression. A compiled expression consists of a bunch of Regexp subclasses linked together in a double linked list. The only reason for prev pointers is to easily handled Multi processing, where you have to splice into the list sometimes.


match

protected boolean match(starwave.util.regexp.State state)
Walks as far as it can down a regular expression, returning true if it made it all the way to the end, and false otherwise. When false, restores state to original state.


match

public Result match(java.lang.String data,
                    int offset)
Returns true if the specified String is matched by this regular expression. This is not to be confused with search, which looks all through the string for a match. This just looks to see if the beginning of the string matches.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

match

public Result match(char[] data,
                    int offset,
                    int length)
Returns true if the specified String is matched by this regular expression. This is not to be confused with search, which looks all through the string for a match. This just looks to see if the beginning of the string matches.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

searchForward

public final Result searchForward(java.lang.String data,
                                  int offset)
Returns true if the specified String is matched anywhere by this regular expression. This is not like match, which only matches at the beginning of the string. This searches through the whole string starting at the specified offset looking for a match.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

searchForward

public final Result searchForward(char[] data,
                                  int offset,
                                  int length)
Returns true if the specified char array is matched anywhere by this regular expression. This is not like match, which only matches at the beginning of the string. This searches through the whole string starting at the specified offset looking for a match.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

searchBackward

public Result searchBackward(java.lang.String data,
                             int offset)
Returns true if the specified String is matched from the specified offset backward by this regular expression. This is not like match, which only matches at the beginning of the string. This searches through the whole string starting at the specified offset looking for a match.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

searchBackward

public Result searchBackward(char[] data,
                             int offset,
                             int length)
Returns true if the specified char array is matched from the specified offset backward by this regular expression. This is not like match, which only matches at the beginning of the string. This searches through the whole string starting at the specified offset looking for a match.

Parameters:
data - string to match
Returns:
a regexp.Result on success, null on failure
See Also:
Result

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
java.lang.Exception

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

toStringThis

public java.lang.String toStringThis()