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 * A special optimization of multi that is used when the common subpattern ".*"
\r
16 class DotMulti extends PatternSub
\r
18 patInt fewestMatches, mostMatches;
\r
20 public patInt minChars()
\r
22 return fewestMatches;
\r
25 public patInt maxChars()
\r
30 public boolean matchFewest = false;
\r
32 StringLike src = null;
\r
36 boolean dotDoesntMatchCR = true;
\r
38 DotMulti(patInt a, patInt b)
\r
44 public String toString()
\r
46 return ".{" + fewestMatches + "," + mostMatches + "}"
\r
47 + (matchFewest ? "?" : "") + "(?# <= dot multi)" + nextString();
\r
50 final int submatchInternal(int pos, Pthings pt)
\r
52 if (pos < srclength)
\r
54 if (dotDoesntMatchCR)
\r
56 if (src.charAt(pos) != '\n')
\r
69 final static int step = 1;
\r
71 static int idcount = 1;
\r
73 public int matchInternal(int pos, Pthings pt)
\r
78 srclength = src.length();
\r
79 dotDoesntMatchCR = pt.dotDoesntMatchCR;
\r
83 while (fewestMatches.intValue() > nMatches)
\r
85 i = submatchInternal(i, pt);
\r
96 int ii = nextMatch(i, pt);
\r
101 if (!mostMatches.finite())
\r
105 i = submatchInternal(i, pt);
\r
110 ii = nextMatch(i, pt);
\r
121 i = submatchInternal(i, pt);
\r
127 if (nMatches > mostMatches.intValue())
\r
131 ii = nextMatch(i, pt);
\r
141 while (fewestMatches.intValue() > nMatches)
\r
143 i = submatchInternal(i, pt);
\r
154 if (mostMatches.finite())
\r
156 while (nMatches < mostMatches.intValue())
\r
158 i = submatchInternal(i, pt);
\r
174 i = submatchInternal(i, pt);
\r
188 int r = nextMatch(m, pt);
\r
195 if (nMatches < fewestMatches.intValue())
\r
203 Pattern clone1(Hashtable h)
\r
205 DotMulti dm = new DotMulti(fewestMatches, mostMatches);
\r
206 dm.matchFewest = matchFewest;
\r