2 // This software is now distributed according to
\r
3 // the Lesser Gnu Public License. Please see
\r
4 // http://www.gnu.org/copyleft/lesser.txt for
\r
6 // -- Happy Computing!
\r
8 package com.stevesoft.pat;
\r
9 import java.util.Hashtable;
\r
11 /** Thrown when one encounters things like [z-a] */
\r
12 class BadRangeArgs extends RegSyntax {};
\r
14 /** Implments a subelement (ranges) of the [] pattern element.
\r
15 For example, [a-z023] is implemented using a range and tree oneChar
\r
20 class Range extends Pattern {
\r
21 char lo,hi,altlo,althi;
\r
22 boolean printBrackets = false;
\r
23 public String toString() {
\r
24 String s=protect(""+lo,PROTECT_THESE,ESC)+"-"
\r
25 +protect(""+hi,PROTECT_THESE,ESC);
\r
30 Range(char loi,char hii) throws RegSyntax {
\r
34 //throw new BadRangeArgs();
\r
35 RegSyntaxError.endItAll("Badly formed []'s : "+lo+" >= "+hi);
\r
36 o = new oneChar(lo);
\r
38 o = new oneChar(hi);
\r
41 public int matchInternal(int pos,Pthings pt) {
\r
42 if(pos >= pt.src.length()) return -1;
\r
43 if(Masked(pos,pt)) return -1;
\r
44 char c = pt.src.charAt(pos);
\r
45 if(lo <= c && c <= hi ||
\r
46 (pt.ignoreCase && (altlo <= c && c <= althi)))
\r
47 return nextMatch(pos+1,pt);
\r
50 public patInt minChars() { return new patInt(1); }
\r
51 public patInt maxChars() { return new patInt(1); }
\r
52 public Pattern clone1(Hashtable h) {
\r
54 Range r = new Range(lo,hi);
\r
55 r.printBrackets = printBrackets;
\r
57 } catch(RegSyntax rs) {
\r