Clover icon

Coverage Report

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

File Range.java

 

Coverage histogram

../../../img/srcFileCovDistChart8.png
20% of files have more coverage

Code metrics

10
28
6
2
97
71
16
0.57
4.67
3
2.67

Classes

Class Line # Actions
BadRangeArgs 13 0 0
-1.0 -
Range 24 28 16
0.7272727572.7%
 

Contributing tests

This file is covered by 29 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    /** Thrown when one encounters things like [z-a] */
 
13    class BadRangeArgs extends RegSyntax
14    {
15    };
16   
17    /**
18    * Implments a subelement (ranges) of the [] pattern element. For example,
19    * [a-z023] is implemented using a range and tree oneChar classes.
20    *
21    * @see Bracket
22    * @see oneChar
23    */
 
24    class Range extends Pattern
25    {
26    char lo, hi, altlo, althi;
27   
28    boolean printBrackets = false;
29   
 
30  0 toggle public String toString()
31    {
32  0 String s = protect("" + lo, PROTECT_THESE, ESC) + "-"
33    + protect("" + hi, PROTECT_THESE, ESC);
34  0 if (!printBrackets)
35    {
36  0 return s;
37    }
38  0 return "[" + s + "]";
39    }
40   
 
41  6745 toggle Range(char loi, char hii) throws RegSyntax
42    {
43  6745 lo = loi;
44  6745 hi = hii;
45  6745 oneChar o = null;
46  6745 if (lo >= hi)
47    {
48    // throw new BadRangeArgs();
49  0 RegSyntaxError.endItAll("Badly formed []'s : " + lo + " >= " + hi);
50    }
51  6745 o = new oneChar(lo);
52  6745 altlo = o.altc;
53  6745 o = new oneChar(hi);
54  6745 althi = o.altc;
55    }
56   
 
57  32882 toggle public int matchInternal(int pos, Pthings pt)
58    {
59  32882 if (pos >= pt.src.length())
60    {
61  684 return -1;
62    }
63  32198 if (Masked(pos, pt))
64    {
65  0 return -1;
66    }
67  32198 char c = pt.src.charAt(pos);
68  32198 if (lo <= c && c <= hi || (pt.ignoreCase && (altlo <= c && c <= althi)))
69    {
70  10306 return nextMatch(pos + 1, pt);
71    }
72  21892 return -1;
73    }
74   
 
75  586 toggle public patInt minChars()
76    {
77  586 return new patInt(1);
78    }
79   
 
80  2 toggle public patInt maxChars()
81    {
82  2 return new patInt(1);
83    }
84   
 
85  2254 toggle public Pattern clone1(Hashtable h)
86    {
87  2254 try
88    {
89  2254 Range r = new Range(lo, hi);
90  2254 r.printBrackets = printBrackets;
91  2254 return r;
92    } catch (RegSyntax rs)
93    {
94  0 return null;
95    }
96    }
97    };