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 /** If Multi were not split into a second stage, then
\r
13 a nested Multi would try to re-use the same count
\r
14 variable and the whole thing would break. */
\r
20 patInt matchMin, matchMax;
\r
21 public boolean matchFewest = false;
\r
22 public String toString()
\r
25 ret += sub.toString();
\r
26 ret += "{" + matchMin + "," + matchMax + "}";
\r
31 ret += parent.nextString();
\r
35 Multi_stage2(patInt a, patInt b, Pattern p)
\r
40 RegSyntaxError.endItAll(
\r
41 "Multiple match of Null pattern requested.");
\r
45 sub.setParent(this);
\r
48 count = new patInt(0);
\r
49 // we must have b > a > -1 for this
\r
53 //throw new BadMultiArgs();
\r
54 RegSyntaxError.endItAll("Bad Multi Args: " + a + ">" + b);
\r
56 patInt i = new patInt( -1);
\r
59 //throw new BadMultiArgs();
\r
60 RegSyntaxError.endItAll("Bad Multi Args: " + a + "< 0");
\r
64 public Pattern getNext()
\r
70 public int matchInternal(int pos, Pthings pt)
\r
72 sub.setParent(this);
\r
76 // check for some forms of infinite recursion...
\r
77 if (pos_old >= 0 && pos == pos_old)
\r
83 if (matchMin.lessEq(count))
\r
87 if (!count.lessEq(matchMax) || pos > pt.src.length())
\r
92 if ( (matchFewest || count.equals(matchMax)) && canUse >= 0)
\r
94 Pattern n = super.getNext();
\r
99 int ret = testMatch(n, pos, pt);
\r
113 if (count.lessEq(matchMax))
\r
115 int r = testMatch(sub, pos, pt);
\r
127 if (!matchFewest && canUse >= 0)
\r
129 Pattern n = super.getNext();
\r
134 int ret = testMatch(n, pos, pt);
\r
143 public Pattern clone1(Hashtable h)
\r
147 Multi_stage2 m = new Multi_stage2(matchMin, matchMax, sub.clone(h));
\r
148 m.matchFewest = matchFewest;
\r
151 catch (RegSyntax rs)
\r