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
13 * If Multi were not split into a second stage, then a nested Multi would try to
\r
14 * re-use the same count variable and the whole thing would break.
\r
16 class Multi_stage2 extends PatternSub
\r
22 patInt matchMin, matchMax;
\r
24 public boolean matchFewest = false;
\r
26 public String toString()
\r
29 ret += sub.toString();
\r
30 ret += "{" + matchMin + "," + matchMax + "}";
\r
35 ret += parent.nextString();
\r
39 Multi_stage2(patInt a, patInt b, Pattern p) throws RegSyntax
\r
43 RegSyntaxError.endItAll("Multiple match of Null pattern requested.");
\r
47 sub.setParent(this);
\r
50 count = new patInt(0);
\r
51 // we must have b > a > -1 for this
\r
55 // throw new BadMultiArgs();
\r
56 RegSyntaxError.endItAll("Bad Multi Args: " + a + ">" + b);
\r
58 patInt i = new patInt(-1);
\r
61 // throw new BadMultiArgs();
\r
62 RegSyntaxError.endItAll("Bad Multi Args: " + a + "< 0");
\r
66 public Pattern getNext()
\r
73 public int matchInternal(int pos, Pthings pt)
\r
75 sub.setParent(this);
\r
79 // check for some forms of infinite recursion...
\r
80 if (pos_old >= 0 && pos == pos_old)
\r
86 if (matchMin.lessEq(count))
\r
90 if (!count.lessEq(matchMax) || pos > pt.src.length())
\r
95 if ((matchFewest || count.equals(matchMax)) && canUse >= 0)
\r
97 Pattern n = super.getNext();
\r
102 int ret = testMatch(n, pos, pt);
\r
116 if (count.lessEq(matchMax))
\r
118 int r = testMatch(sub, pos, pt);
\r
129 if (!matchFewest && canUse >= 0)
\r
131 Pattern n = super.getNext();
\r
136 int ret = testMatch(n, pos, pt);
\r
145 public Pattern clone1(Hashtable h)
\r
149 Multi_stage2 m = new Multi_stage2(matchMin, matchMax, sub.clone(h));
\r
150 m.matchFewest = matchFewest;
\r
152 } catch (RegSyntax rs)
\r