All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class pat.Pattern

java.lang.Object
   |
   +----pat.Pattern

public class Pattern
extends Object
Shareware: package pat Copyright 1996, Steven R. Brandt

Class Pattern is a way of doing regexp-like things. The idea is to build a chain of objects, each of which can match part of a Pattern. This package also contains a Regex class which handles the parsing for these objects -- but the parsing routine is kept strictly separate from the base Pattern object. The base Pattern object does not depend on Regex at all. The chains may be built using the add() member function. For example:

Pattern p = (new oneChar('a')).add(new oneChar('b')).add(
new oneChar('c'));
provides a Pattern which matches the String "abc". And thus, p.match("abc") will return 3, the number of characters matched.

This is, of course, a non-standard way to build regular expressions. The standard way is provided by class Regex.

A partial list of the patterns provided:

Range(char a,char b) matches a character between character a and b inclusive. Range('a','z') matches all lowercase letters.
Multi(patInt a,patInt b,Pattern p) matches between a and b instances of Pattern p. patInt can be instantiated by either new patInt(int x), or new patInf() for infinity.
Or() matches one of a chain of patterns. To instantiate an Or object, you can write (new Or()).addOr(Pattern p1).addOr(Pattern p2)... chaining as many objects as you wish.
Start(boolean b) matches the start of a String. If b is true then a carriage return will match Start as well as the start of a String.
End(boolean b) matches the end of a String. If b is true then a carriage return will match End as well as the end of a string.
oneChar(char c) matches the character c.
Any() matches any character.


Variable Index

 o ESC
The ESC character, the user can provide his own value for the escape character through regex.esc

Constructor Index

 o Pattern()

Method Index

 o add(Pattern)
add a Pattern to the singly-linked Pattern chain.
 o countMaxChars()
return maximum number of characters in pattern
 o countMinChars()
return minimum number of characters in pattern
 o getNext()
This gets the next element of a Pattern that we wish to match.
 o match(String, Pthings)
This can be used to perform a match test from within class Pattern.
 o matchAt(String, int, Pthings)
This can be used to perform a match test from within class Pattern.
 o matchInternal(int, Pthings)
The interal match function, it must be provided by any class which wishes to extend Pattern.
 o maxChars()
Method to over-ride when making your own patterns.
 o minChars()
Method to over-ride when making your own patterns.
 o nextMatch(int, Pthings)
This determines if the remainder of a Pattern matches.
 o nextString()
This is a toString() for the remainder of the Pattern elements after this one.
 o setParent(Pattern)
Call this method if you have a pattern element that takes a sub pattern (such as Or), and after you have added a sub pattern to the current pattern element.
 o toString()
Conversion to a String

Variables

 o ESC
  public final static char ESC
The ESC character, the user can provide his own value for the escape character through regex.esc

Constructors

 o Pattern
  public Pattern()

Methods

 o matchInternal
  public abstract int matchInternal(int i,
                                    Pthings p)
The interal match function, it must be provided by any class which wishes to extend Pattern.

 o toString
  public abstract String toString()
Conversion to a String

Overrides:
toString in class Object
 o getNext
  public Pattern getNext()
This gets the next element of a Pattern that we wish to match. If we are at the end of a subchain of patterns, it will return us to the parent chain.

 o setParent
  public void setParent(Pattern p)
Call this method if you have a pattern element that takes a sub pattern (such as Or), and after you have added a sub pattern to the current pattern element.

 o nextMatch
  public int nextMatch(int i,
                       Pthings pt)
This determines if the remainder of a Pattern matches. Type "return nextMatch" from within matchInternal if the current Pattern matches. Otherwise, return a -1.

 o nextString
  public String nextString()
This is a toString() for the remainder of the Pattern elements after this one. use this when overriding toString(). Called from within toString().

 o match
  public int match(String s,
                   Pthings pt)
This can be used to perform a match test from within class Pattern.

 o matchAt
  public int matchAt(String s,
                     int i,
                     Pthings pt)
This can be used to perform a match test from within class Pattern.

 o add
  public Pattern add(Pattern p)
add a Pattern to the singly-linked Pattern chain.

 o minChars
  public patInt minChars()
Method to over-ride when making your own patterns. It is only an optimization. Return the minimum number of characters that can match this pattern element.

 o maxChars
  public patInt maxChars()
Method to over-ride when making your own patterns. It is only an optimization. Return the maximum number of characters that can match this pattern element.

 o countMinChars
  public final patInt countMinChars()
return minimum number of characters in pattern

 o countMaxChars
  public final patInt countMaxChars()
return maximum number of characters in pattern


All Packages  Class Hierarchy  This Package  Previous  Next  Index