Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package com.stevesoft.pat

File DotMulti.java

 

Coverage histogram

../../../img/srcFileCovDistChart5.png
33% 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.4130434741.3%
 

Contributing tests

This file is covered by 12 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  331 toggle DotMulti(patInt a, patInt b)
39    {
40  331 fewestMatches = a;
41  331 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  100580 toggle final int submatchInternal(int pos, Pthings pt)
51    {
52  100580 if (pos < srclength)
53    {
54  97779 if (dotDoesntMatchCR)
55    {
56  97779 if (src.charAt(pos) != '\n')
57    {
58  97779 return 1 + pos;
59    }
60    }
61    else
62    {
63  0 return 1 + pos;
64    }
65    }
66  2801 return -1;
67    }
68   
69    final static int step = 1;
70   
71    static int idcount = 1;
72   
 
73  2827 toggle public int matchInternal(int pos, Pthings pt)
74    {
75  2827 int m = -1;
76  2827 int i = pos;
77  2827 src = pt.src;
78  2827 srclength = src.length();
79  2827 dotDoesntMatchCR = pt.dotDoesntMatchCR;
80  2827 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  2827 int nMatches = 0;
141  2827 while (fewestMatches.intValue() > nMatches)
142    {
143  0 i = submatchInternal(i, pt);
144  0 if (i >= 0)
145    {
146  0 nMatches++;
147    }
148    else
149    {
150  0 return -1;
151    }
152    }
153  2827 m = i;
154  2827 if (mostMatches.finite())
155    {
156  52 while (nMatches < mostMatches.intValue())
157    {
158  26 i = submatchInternal(i, pt);
159  26 if (i >= 0)
160    {
161  26 m = i;
162  26 nMatches++;
163    }
164    else
165    {
166  0 break;
167    }
168    }
169    }
170    else
171    {
172  2801 while (true)
173    {
174  100554 i = submatchInternal(i, pt);
175  100554 if (i >= 0)
176    {
177  97753 m = i;
178  97753 nMatches++;
179    }
180    else
181    {
182  2801 break;
183    }
184    }
185    }
186  2844 while (m >= pos)
187    {
188  2844 int r = nextMatch(m, pt);
189  2844 if (r >= 0)
190    {
191  2823 return r;
192    }
193  21 m -= step;
194  21 nMatches--;
195  21 if (nMatches < fewestMatches.intValue())
196    {
197  4 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    }