Clover icon

Coverage Report

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

File Range.java

 

Coverage histogram

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