2 // This software is now distributed according to
\r
3 // the Lesser Gnu Public License. Please see
\r
4 // http://www.gnu.org/copyleft/lesser.txt for
\r
6 // -- Happy Computing!
\r
8 package com.stevesoft.pat;
\r
12 /** This class implements the (?: ... ) extended Pattern.
\r
13 It provides a base class from which we derive the
\r
14 [ ... ], ( ... ), (?! ... ), and (?= ... ) patterns. */
\r
15 class Or extends Pattern {
\r
17 Pattern[] pv = null;
\r
18 Or() { v = new Vector(); }
\r
19 String leftForm() { return "(?:"; }
\r
20 String rightForm() { return ")"; }
\r
21 String sepForm() { return "|"; }
\r
22 public Or addOr(Pattern p) {
\r
28 public String toString() {
\r
30 StringBuffer sb = new StringBuffer();
\r
31 sb.append(leftForm());
\r
33 sb.append( ((Pattern)v.elementAt(0)).toString() );
\r
34 for(i=1;i<v.size();i++) {
\r
35 sb.append(sepForm());
\r
36 sb.append( ((Pattern)v.elementAt(i)).toString() );
\r
38 sb.append(rightForm());
\r
39 sb.append(nextString());
\r
40 return sb.toString();
\r
42 public int matchInternal(int pos,Pthings pt) {
\r
44 pv = new Pattern[v.size()];
\r
47 for(int i=0;i<v.size();i++) {
\r
48 Pattern p = pv[i];//(Pattern)v.elementAt(i);
\r
49 int r = p.matchInternal(pos,pt);
\r
55 public patInt minChars() {
\r
56 if(v.size()==0) return new patInt(0);
\r
57 patInt m = ((Pattern)v.elementAt(0)).countMinChars();
\r
58 for(int i=1;i<v.size();i++) {
\r
59 Pattern p = (Pattern)v.elementAt(i);
\r
60 m.mineq(p.countMinChars());
\r
64 public patInt maxChars() {
\r
65 if(v.size()==0) return new patInt(0);
\r
66 patInt m = ((Pattern)v.elementAt(0)).countMaxChars();
\r
67 for(int i=1;i<v.size();i++) {
\r
68 Pattern p = (Pattern)v.elementAt(i);
\r
69 m.maxeq(p.countMaxChars());
\r
73 Pattern clone1(Hashtable h) {
\r
77 for(int i=0;i<v.size();i++)
\r
78 o.v.addElement( ((Pattern)v.elementAt(i)).clone(h) );
\r