--- /dev/null
+//\r
+// This software is now distributed according to\r
+// the Lesser Gnu Public License. Please see\r
+// http://www.gnu.org/copyleft/lesser.txt for\r
+// the details.\r
+// -- Happy Computing!\r
+//\r
+package com.stevesoft.pat;\r
+import java.util.Hashtable;\r
+\r
+/** Thrown when one encounters things like [z-a] */\r
+class BadRangeArgs extends RegSyntax {};\r
+\r
+/** Implments a subelement (ranges) of the [] pattern element.\r
+For example, [a-z023] is implemented using a range and tree oneChar\r
+classes.\r
+@see Bracket\r
+@see oneChar\r
+*/\r
+class Range extends Pattern {\r
+ char lo,hi,altlo,althi;\r
+ boolean printBrackets = false;\r
+ public String toString() {\r
+ String s=protect(""+lo,PROTECT_THESE,ESC)+"-"\r
+ +protect(""+hi,PROTECT_THESE,ESC);\r
+ if(!printBrackets)\r
+ return s;\r
+ return "["+s+"]";\r
+ }\r
+ Range(char loi,char hii) throws RegSyntax {\r
+ lo = loi; hi = hii;\r
+ oneChar o = null;\r
+ if(lo >= hi)\r
+ //throw new BadRangeArgs();\r
+ RegSyntaxError.endItAll("Badly formed []'s : "+lo+" >= "+hi);\r
+ o = new oneChar(lo);\r
+ altlo = o.altc;\r
+ o = new oneChar(hi);\r
+ althi = o.altc;\r
+ }\r
+ public int matchInternal(int pos,Pthings pt) {\r
+ if(pos >= pt.src.length()) return -1;\r
+ if(Masked(pos,pt)) return -1;\r
+ char c = pt.src.charAt(pos);\r
+ if(lo <= c && c <= hi ||\r
+ (pt.ignoreCase && (altlo <= c && c <= althi)))\r
+ return nextMatch(pos+1,pt);\r
+ return -1;\r
+ }\r
+ public patInt minChars() { return new patInt(1); }\r
+ public patInt maxChars() { return new patInt(1); }\r
+ public Pattern clone1(Hashtable h) {\r
+ try {\r
+ Range r = new Range(lo,hi);\r
+ r.printBrackets = printBrackets;\r
+ return r;\r
+ } catch(RegSyntax rs) {\r
+ return null;\r
+ }\r
+ }\r
+};\r