Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package com.stevesoft.pat

File DotMulti.java

 

Coverage histogram

../../../img/srcFileCovDistChart5.png
39% 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 14 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  352 toggle DotMulti(patInt a, patInt b)
39    {
40  352 fewestMatches = a;
41  352 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  117060 toggle final int submatchInternal(int pos, Pthings pt)
51    {
52  117060 if (pos < srclength)
53    {
54  113981 if (dotDoesntMatchCR)
55    {
56  113981 if (src.charAt(pos) != '\n')
57    {
58  113981 return 1 + pos;
59    }
60    }
61    else
62    {
63  0 return 1 + pos;
64    }
65    }
66  3079 return -1;
67    }
68   
69    final static int step = 1;
70   
71    static int idcount = 1;
72   
 
73  3106 toggle public int matchInternal(int pos, Pthings pt)
74    {
75  3106 int m = -1;
76  3106 int i = pos;
77  3106 src = pt.src;
78  3106 srclength = src.length();
79  3106 dotDoesntMatchCR = pt.dotDoesntMatchCR;
80  3106 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  3106 int nMatches = 0;
141  3110 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  3088 m = i;
154  3088 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  3061 while (true)
173    {
174  117011 i = submatchInternal(i, pt);
175  117011 if (i >= 0)
176    {
177  113950 m = i;
178  113950 nMatches++;
179    }
180    else
181    {
182  3061 break;
183    }
184    }
185    }
186  3249 while (m >= pos)
187    {
188  3249 int r = nextMatch(m, pt);
189  3249 if (r >= 0)
190    {
191  3065 return r;
192    }
193  184 m -= step;
194  184 nMatches--;
195  184 if (nMatches < fewestMatches.intValue())
196    {
197  23 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    }