Clover icon

Coverage Report

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

File Range.java

 

Coverage histogram

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