X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fcom%2Fstevesoft%2Fpat%2FRange.java;h=02c5d3a5aa30e890a058a148c54aa42cb985ae43;hb=1903e771d3dae79e9a57fcc1147efd37e8a51421;hp=5d5f9a1d7bc848e135342dd213927c157c948c68;hpb=c40cf903f740a72ab63dd1abc10fa33450ce660d;p=jalview.git diff --git a/src/com/stevesoft/pat/Range.java b/src/com/stevesoft/pat/Range.java index 5d5f9a1..02c5d3a 100755 --- a/src/com/stevesoft/pat/Range.java +++ b/src/com/stevesoft/pat/Range.java @@ -1,61 +1,97 @@ -// -// This software is now distributed according to -// the Lesser Gnu Public License. Please see -// http://www.gnu.org/copyleft/lesser.txt for -// the details. -// -- Happy Computing! -// -package com.stevesoft.pat; -import java.util.Hashtable; - -/** Thrown when one encounters things like [z-a] */ -class BadRangeArgs extends RegSyntax {}; - -/** Implments a subelement (ranges) of the [] pattern element. -For example, [a-z023] is implemented using a range and tree oneChar -classes. -@see Bracket -@see oneChar -*/ -class Range extends Pattern { - char lo,hi,altlo,althi; - boolean printBrackets = false; - public String toString() { - String s=protect(""+lo,PROTECT_THESE,ESC)+"-" - +protect(""+hi,PROTECT_THESE,ESC); - if(!printBrackets) - return s; - return "["+s+"]"; - } - Range(char loi,char hii) throws RegSyntax { - lo = loi; hi = hii; - oneChar o = null; - if(lo >= hi) - //throw new BadRangeArgs(); - RegSyntaxError.endItAll("Badly formed []'s : "+lo+" >= "+hi); - o = new oneChar(lo); - altlo = o.altc; - o = new oneChar(hi); - althi = o.altc; - } - public int matchInternal(int pos,Pthings pt) { - if(pos >= pt.src.length()) return -1; - if(Masked(pos,pt)) return -1; - char c = pt.src.charAt(pos); - if(lo <= c && c <= hi || - (pt.ignoreCase && (altlo <= c && c <= althi))) - return nextMatch(pos+1,pt); - return -1; - } - public patInt minChars() { return new patInt(1); } - public patInt maxChars() { return new patInt(1); } - public Pattern clone1(Hashtable h) { - try { - Range r = new Range(lo,hi); - r.printBrackets = printBrackets; - return r; - } catch(RegSyntax rs) { - return null; - } - } -}; +// +// This software is now distributed according to +// the Lesser Gnu Public License. Please see +// http://www.gnu.org/copyleft/lesser.txt for +// the details. +// -- Happy Computing! +// +package com.stevesoft.pat; + +import java.util.Hashtable; + +/** Thrown when one encounters things like [z-a] */ +class BadRangeArgs extends RegSyntax +{ +}; + +/** + * Implments a subelement (ranges) of the [] pattern element. For example, + * [a-z023] is implemented using a range and tree oneChar classes. + * + * @see Bracket + * @see oneChar + */ +class Range extends Pattern +{ + char lo, hi, altlo, althi; + + boolean printBrackets = false; + + public String toString() + { + String s = protect("" + lo, PROTECT_THESE, ESC) + "-" + + protect("" + hi, PROTECT_THESE, ESC); + if (!printBrackets) + { + return s; + } + return "[" + s + "]"; + } + + Range(char loi, char hii) throws RegSyntax + { + lo = loi; + hi = hii; + oneChar o = null; + if (lo >= hi) + { + // throw new BadRangeArgs(); + RegSyntaxError.endItAll("Badly formed []'s : " + lo + " >= " + hi); + } + o = new oneChar(lo); + altlo = o.altc; + o = new oneChar(hi); + althi = o.altc; + } + + public int matchInternal(int pos, Pthings pt) + { + if (pos >= pt.src.length()) + { + return -1; + } + if (Masked(pos, pt)) + { + return -1; + } + char c = pt.src.charAt(pos); + if (lo <= c && c <= hi || (pt.ignoreCase && (altlo <= c && c <= althi))) + { + return nextMatch(pos + 1, pt); + } + return -1; + } + + public patInt minChars() + { + return new patInt(1); + } + + public patInt maxChars() + { + return new patInt(1); + } + + public Pattern clone1(Hashtable h) + { + try + { + Range r = new Range(lo, hi); + r.printBrackets = printBrackets; + return r; + } catch (RegSyntax rs) + { + return null; + } + } +};