2 // This software is now distributed according to
3 // the Lesser Gnu Public License. Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
8 package com.stevesoft.pat;
10 import java.util.Hashtable;
11 import java.util.Vector;
14 * This class implements the (?: ... ) extended Pattern. It provides a base
15 * class from which we derive the [ ... ], ( ... ), (?! ... ), and (?= ... )
18 class Or extends Pattern
44 public Or addOr(Pattern p)
52 public String toString()
55 StringBuffer sb = new StringBuffer();
56 sb.append(leftForm());
59 sb.append(((Pattern) v.elementAt(0)).toString());
61 for (i = 1; i < v.size(); i++)
64 sb.append(((Pattern) v.elementAt(i)).toString());
66 sb.append(rightForm());
67 sb.append(nextString());
71 public int matchInternal(int pos, Pthings pt)
75 pv = new Pattern[v.size()];
78 for (int i = 0; i < v.size(); i++)
80 Pattern p = pv[i]; // (Pattern)v.elementAt(i);
81 int r = p.matchInternal(pos, pt);
90 public patInt minChars()
96 patInt m = ((Pattern) v.elementAt(0)).countMinChars();
97 for (int i = 1; i < v.size(); i++)
99 Pattern p = (Pattern) v.elementAt(i);
100 m.mineq(p.countMinChars());
105 public patInt maxChars()
109 return new patInt(0);
111 patInt m = ((Pattern) v.elementAt(0)).countMaxChars();
112 for (int i = 1; i < v.size(); i++)
114 Pattern p = (Pattern) v.elementAt(i);
115 m.maxeq(p.countMaxChars());
120 Pattern clone1(Hashtable h)
125 for (int i = 0; i < v.size(); i++)
127 o.v.addElement(((Pattern) v.elementAt(i)).clone(h));