Clover icon

Coverage Report

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

File Multi_stage2.java

 

Coverage histogram

../../../img/srcFileCovDistChart6.png
33% of files have more coverage

Code metrics

28
57
5
1
157
124
25
0.44
11.4
5
5

Classes

Class Line # Actions
Multi_stage2 16 57 25
0.522222252.2%
 

Contributing tests

This file is covered by 2 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    * If Multi were not split into a second stage, then a nested Multi would try to
14    * re-use the same count variable and the whole thing would break.
15    */
 
16    class Multi_stage2 extends PatternSub
17    {
18    Pattern nextRet;
19   
20    patInt count;
21   
22    patInt matchMin, matchMax;
23   
24    public boolean matchFewest = false;
25   
 
26  0 toggle public String toString()
27    {
28  0 String ret = "";
29  0 ret += sub.toString();
30  0 ret += "{" + matchMin + "," + matchMax + "}";
31  0 if (matchFewest)
32    {
33  0 ret += "?";
34    }
35  0 ret += parent.nextString();
36  0 return ret;
37    }
38   
 
39  16 toggle Multi_stage2(patInt a, patInt b, Pattern p) throws RegSyntax
40    {
41  16 if (p == null)
42    {
43  0 RegSyntaxError.endItAll("Multiple match of Null pattern requested.");
44    }
45  16 sub = p;
46  16 nextRet = this;
47  16 sub.setParent(this);
48  16 matchMin = a;
49  16 matchMax = b;
50  16 count = new patInt(0);
51    // we must have b > a > -1 for this
52    // to make sense.
53  16 if (!a.lessEq(b))
54    {
55    // throw new BadMultiArgs();
56  0 RegSyntaxError.endItAll("Bad Multi Args: " + a + ">" + b);
57    }
58  16 patInt i = new patInt(-1);
59  16 if (a.lessEq(i))
60    {
61    // throw new BadMultiArgs();
62  0 RegSyntaxError.endItAll("Bad Multi Args: " + a + "< 0");
63    }
64    }
65   
 
66  350 toggle public Pattern getNext()
67    {
68  350 return nextRet;
69    }
70   
71    int pos_old = -1;
72   
 
73  350 toggle public int matchInternal(int pos, Pthings pt)
74    {
75  350 sub.setParent(this);
76   
77  350 int canUse = -1;
78   
79    // check for some forms of infinite recursion...
80  350 if (pos_old >= 0 && pos == pos_old)
81    {
82  0 return -1;
83    }
84  350 pos_old = pos;
85   
86  350 if (matchMin.lessEq(count))
87    {
88  342 canUse = pos;
89    }
90  350 if (!count.lessEq(matchMax) || pos > pt.src.length())
91    {
92  0 return -1;
93    }
94   
95  350 if ((matchFewest || count.equals(matchMax)) && canUse >= 0)
96    {
97  0 Pattern n = super.getNext();
98  0 if (n == null)
99    {
100  0 return canUse;
101    }
102  0 int ret = testMatch(n, pos, pt);
103  0 if (ret >= 0)
104    {
105  0 return ret;
106    }
107    else
108    {
109  0 canUse = -1;
110    }
111    }
112   
113  350 count.inc();
114  350 try
115    {
116  350 if (count.lessEq(matchMax))
117    {
118  350 int r = testMatch(sub, pos, pt);
119  350 if (r >= 0)
120    {
121  342 return r;
122    }
123    }
124    } finally
125    {
126  350 count.dec();
127    }
128   
129  8 if (!matchFewest && canUse >= 0)
130    {
131  8 Pattern n = super.getNext();
132  8 if (n == null)
133    {
134  0 return canUse;
135    }
136  8 int ret = testMatch(n, pos, pt);
137  8 return ret;
138    }
139    else
140    {
141  0 return canUse;
142    }
143    }
144   
 
145  0 toggle public Pattern clone1(Hashtable h)
146    {
147  0 try
148    {
149  0 Multi_stage2 m = new Multi_stage2(matchMin, matchMax, sub.clone(h));
150  0 m.matchFewest = matchFewest;
151  0 return m;
152    } catch (RegSyntax rs)
153    {
154  0 return null;
155    }
156    }
157    };