Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package com.stevesoft.pat

File DotMulti.java

 

Coverage histogram

../../../img/srcFileCovDistChart5.png
43% of files have more coverage

Code metrics

52
79
7
1
209
183
33
0.42
11.29
7
4.71

Classes

Class Line # Actions
DotMulti 16 79 33
0.4637681246.4%
 

Contributing tests

This file is covered by 16 tests. .

Source view

1    //
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
5    // the details.
6    // -- Happy Computing!
7    //
8    package com.stevesoft.pat;
9   
10    import java.util.Hashtable;
11   
12    /**
13    * A special optimization of multi that is used when the common subpattern ".*"
14    * is encountered.
15    */
 
16    class DotMulti extends PatternSub
17    {
18    patInt fewestMatches, mostMatches;
19   
 
20  0 toggle public patInt minChars()
21    {
22  0 return fewestMatches;
23    }
24   
 
25  0 toggle public patInt maxChars()
26    {
27  0 return mostMatches;
28    }
29   
30    public boolean matchFewest = false;
31   
32    StringLike src = null;
33   
34    int srclength = 0;
35   
36    boolean dotDoesntMatchCR = true;
37   
 
38  371 toggle DotMulti(patInt a, patInt b)
39    {
40  371 fewestMatches = a;
41  371 mostMatches = b;
42    }
43   
 
44  0 toggle public String toString()
45    {
46  0 return ".{" + fewestMatches + "," + mostMatches + "}"
47  0 + (matchFewest ? "?" : "") + "(?# <= dot multi)" + nextString();
48    }
49   
 
50  118907 toggle final int submatchInternal(int pos, Pthings pt)
51    {
52  118907 if (pos < srclength)
53    {
54  115767 if (dotDoesntMatchCR)
55    {
56  115767 if (src.charAt(pos) != '\n')
57    {
58  115767 return 1 + pos;
59    }
60    }
61    else
62    {
63  0 return 1 + pos;
64    }
65    }
66  3140 return -1;
67    }
68   
69    final static int step = 1;
70   
71    static int idcount = 1;
72   
 
73  3167 toggle public int matchInternal(int pos, Pthings pt)
74    {
75  3167 int m = -1;
76  3167 int i = pos;
77  3167 src = pt.src;
78  3167 srclength = src.length();
79  3167 dotDoesntMatchCR = pt.dotDoesntMatchCR;
80  3167 if (matchFewest)
81    {
82  0 int nMatches = 0;
83  0 while (fewestMatches.intValue() > nMatches)
84    {
85  0 i = submatchInternal(i, pt);
86  0 if (i < 0)
87    {
88  0 return -1;
89    }
90  0 nMatches++;
91    }
92  0 if (i < 0)
93    {
94  0 return -1;
95    }
96  0 int ii = nextMatch(i, pt);
97  0 if (ii >= 0)
98    {
99  0 return ii;
100    }
101  0 if (!mostMatches.finite())
102    {
103  0 while (i >= 0)
104    {
105  0 i = submatchInternal(i, pt);
106  0 if (i < 0)
107    {
108  0 return -1;
109    }
110  0 ii = nextMatch(i, pt);
111  0 if (ii >= 0)
112    {
113  0 return ii;
114    }
115    }
116    }
117    else
118    {
119  0 while (i > 0)
120    {
121  0 i = submatchInternal(i, pt);
122  0 if (i < 0)
123    {
124  0 return -1;
125    }
126  0 nMatches++;
127  0 if (nMatches > mostMatches.intValue())
128    {
129  0 return -1;
130    }
131  0 ii = nextMatch(i, pt);
132  0 if (ii >= 0)
133    {
134  0 return ii;
135    }
136    }
137    }
138  0 return -1;
139    }
140  3167 int nMatches = 0;
141  3171 while (fewestMatches.intValue() > nMatches)
142    {
143  22 i = submatchInternal(i, pt);
144  22 if (i >= 0)
145    {
146  4 nMatches++;
147    }
148    else
149    {
150  18 return -1;
151    }
152    }
153  3149 m = i;
154  3149 if (mostMatches.finite())
155    {
156  54 while (nMatches < mostMatches.intValue())
157    {
158  27 i = submatchInternal(i, pt);
159  27 if (i >= 0)
160    {
161  27 m = i;
162  27 nMatches++;
163    }
164    else
165    {
166  0 break;
167    }
168    }
169    }
170    else
171    {
172  3122 while (true)
173    {
174  118858 i = submatchInternal(i, pt);
175  118858 if (i >= 0)
176    {
177  115736 m = i;
178  115736 nMatches++;
179    }
180    else
181    {
182  3122 break;
183    }
184    }
185    }
186  3327 while (m >= pos)
187    {
188  3327 int r = nextMatch(m, pt);
189  3327 if (r >= 0)
190    {
191  3122 return r;
192    }
193  205 m -= step;
194  205 nMatches--;
195  205 if (nMatches < fewestMatches.intValue())
196    {
197  27 return -1;
198    }
199    }
200  0 return -1;
201    }
202   
 
203  0 toggle Pattern clone1(Hashtable h)
204    {
205  0 DotMulti dm = new DotMulti(fewestMatches, mostMatches);
206  0 dm.matchFewest = matchFewest;
207  0 return dm;
208    }
209    }