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