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.
-
ESC
- The ESC character, the user can provide his own value
for the escape character through regex.esc
-
Pattern()
-
-
add(Pattern)
- add a Pattern to the singly-linked Pattern chain.
-
countMaxChars()
- return maximum number of characters in pattern
-
countMinChars()
- return minimum number of characters in pattern
-
getNext()
- This gets the next element of a Pattern that
we wish to match.
-
match(String, Pthings)
- This can be used to perform a match test from
within class Pattern.
-
matchAt(String, int, Pthings)
- This can be used to perform a match test from
within class Pattern.
-
matchInternal(int, Pthings)
- The interal match function, it must be provided by any
class which wishes to extend Pattern.
-
maxChars()
- Method to over-ride when making your own
patterns.
-
minChars()
- Method to over-ride when making your own
patterns.
-
nextMatch(int, Pthings)
- This determines if the remainder of a Pattern
matches.
-
nextString()
- This is a toString() for the remainder
of the Pattern elements after this one.
-
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.
-
toString()
- Conversion to a String
ESC
public final static char ESC
- The ESC character, the user can provide his own value
for the escape character through regex.esc
Pattern
public Pattern()
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.
toString
public abstract String toString()
- Conversion to a String
- Overrides:
- toString in class Object
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.
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.
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.
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().
match
public int match(String s,
Pthings pt)
- This can be used to perform a match test from
within class Pattern.
matchAt
public int matchAt(String s,
int i,
Pthings pt)
- This can be used to perform a match test from
within class Pattern.
add
public Pattern add(Pattern p)
- add a Pattern to the singly-linked Pattern chain.
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.
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.
countMinChars
public final patInt countMinChars()
- return minimum number of characters in pattern
countMaxChars
public final patInt countMaxChars()
- return maximum number of characters in pattern
All Packages Class Hierarchy This Package Previous Next Index