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
9 import java.util.Hashtable;
\r
11 /** A special optimization of multi that is used when the
\r
12 * common subpattern ".*" is encountered.
\r
14 class DotMulti extends PatternSub {
\r
15 patInt fewestMatches,mostMatches;
\r
16 public patInt minChars() {
\r
17 return fewestMatches;
\r
19 public patInt maxChars() {
\r
22 public boolean matchFewest = false;
\r
24 StringLike src=null;
\r
26 boolean dotDoesntMatchCR=true;
\r
27 DotMulti(patInt a,patInt b) {
\r
31 public String toString() {
\r
33 +fewestMatches+","+mostMatches+"}"+
\r
34 (matchFewest ? "?" : "")+"(?# <= dot multi)"+
\r
37 final int submatchInternal(int pos,Pthings pt) {
\r
38 if(pos < srclength) {
\r
39 if(dotDoesntMatchCR) {
\r
40 if(src.charAt(pos) != '\n')
\r
42 } else return 1+pos;
\r
46 final static int step = 1;
\r
47 static int idcount = 1;
\r
48 public int matchInternal(int pos,Pthings pt) {
\r
52 srclength = src.length();
\r
53 dotDoesntMatchCR = pt.dotDoesntMatchCR;
\r
56 while(fewestMatches.intValue() > nMatches) {
\r
57 i=submatchInternal(i,pt);
\r
62 int ii = nextMatch(i,pt);
\r
63 if(ii >= 0) return ii;
\r
64 if(!mostMatches.finite()) {
\r
66 i = submatchInternal(i,pt);
\r
67 if(i < 0) return -1;
\r
68 ii = nextMatch(i,pt);
\r
69 if(ii >= 0) return ii;
\r
73 i = submatchInternal(i,pt);
\r
74 if(i < 0) return -1;
\r
76 if(nMatches > mostMatches.intValue())
\r
78 ii = nextMatch(i,pt);
\r
79 if(ii >= 0) return ii;
\r
85 while(fewestMatches.intValue() > nMatches) {
\r
86 i=submatchInternal(i,pt);
\r
93 if(mostMatches.finite()) {
\r
94 while(nMatches < mostMatches.intValue()) {
\r
95 i = submatchInternal(i,pt);
\r
103 i = submatchInternal(i,pt);
\r
111 int r=nextMatch(m,pt);
\r
112 if(r >= 0) return r;
\r
115 if(nMatches < fewestMatches.intValue())
\r
120 Pattern clone1(Hashtable h) {
\r
121 DotMulti dm = new DotMulti(fewestMatches,mostMatches);
\r
122 dm.matchFewest = matchFewest;
\r