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