X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fcom%2Fstevesoft%2Fpat%2FBackMatch.java;h=1d7499e6ad231ce64cba33dff2a93ca0734d2739;hb=4b2392caa53f1de3400e7916d1d9c7b815d446f4;hp=168faecdc303245cd14825007eec6d254b277c66;hpb=c40cf903f740a72ab63dd1abc10fa33450ce660d;p=jalview.git diff --git a/src/com/stevesoft/pat/BackMatch.java b/src/com/stevesoft/pat/BackMatch.java index 168faec..1d7499e 100755 --- a/src/com/stevesoft/pat/BackMatch.java +++ b/src/com/stevesoft/pat/BackMatch.java @@ -1,33 +1,57 @@ -// -// 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; - -/** Provides the ability to match a backreference from within - * a Pattern. - */ -class BackMatch extends Pattern { - int id; - BackMatch(int id) { this.id = id; } - public String toString() { return "\\"+(id)+nextString(); } - public int matchInternal(int pos,Pthings p) { - int i1 = p.marks[id]; - int i2 = p.marks[id+p.nMarks]; - int imax = i2-i1; - if(i1<0||imax < 0||pos+imax>p.src.length()) return -1; - int ns = p.src.length()-pos; - if(imax < ns) ns = imax; - for(int i=0;i p.src.length()) + { + return -1; + } + int ns = p.src.length() - pos; + if (imax < ns) + { + ns = imax; + } + for (int i = 0; i < ns; i++) + { + if (p.src.charAt(i + i1) != p.src.charAt(pos + i)) + { + return -1; + } + } + return nextMatch(pos + imax, p); + } + + Pattern clone1(Hashtable h) + { + return new BackMatch(id); + } +}