Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 11:45:30 GMT
  2. Package com.stevesoft.pat

File Range.java

 

Coverage histogram

../../../img/srcFileCovDistChart8.png
22% 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 83 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  8787 toggle Range(char loi, char hii) throws RegSyntax
42    {
43  8787 lo = loi;
44  8787 hi = hii;
45  8787 oneChar o = null;
46  8787 if (lo >= hi)
47    {
48    // throw new BadRangeArgs();
49  0 RegSyntaxError.endItAll("Badly formed []'s : " + lo + " >= " + hi);
50    }
51  8787 o = new oneChar(lo);
52  8787 altlo = o.altc;
53  8787 o = new oneChar(hi);
54  8787 althi = o.altc;
55    }
56   
 
57  50857 toggle public int matchInternal(int pos, Pthings pt)
58    {
59  50857 if (pos >= pt.src.length())
60    {
61  684 return -1;
62    }
63  50173 if (Masked(pos, pt))
64    {
65  0 return -1;
66    }
67  50173 char c = pt.src.charAt(pos);
68  50173 if (lo <= c && c <= hi || (pt.ignoreCase && (altlo <= c && c <= althi)))
69    {
70  16065 return nextMatch(pos + 1, pt);
71    }
72  34108 return -1;
73    }
74   
 
75  701 toggle public patInt minChars()
76    {
77  701 return new patInt(1);
78    }
79   
 
80  3 toggle public patInt maxChars()
81    {
82  3 return new patInt(1);
83    }
84   
 
85  2744 toggle public Pattern clone1(Hashtable h)
86    {
87  2744 try
88    {
89  2744 Range r = new Range(lo, hi);
90  2744 r.printBrackets = printBrackets;
91  2744 return r;
92    } catch (RegSyntax rs)
93    {
94  0 return null;
95    }
96    }
97    };