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 /** Provides the ability to match a backreference from within
\r
14 class BackMatch extends Pattern {
\r
16 BackMatch(int id) { this.id = id; }
\r
17 public String toString() { return "\\"+(id)+nextString(); }
\r
18 public int matchInternal(int pos,Pthings p) {
\r
19 int i1 = p.marks[id];
\r
20 int i2 = p.marks[id+p.nMarks];
\r
22 if(i1<0||imax < 0||pos+imax>p.src.length()) return -1;
\r
23 int ns = p.src.length()-pos;
\r
24 if(imax < ns) ns = imax;
\r
25 for(int i=0;i<ns;i++) {
\r
26 if(p.src.charAt(i+i1) != p.src.charAt(pos+i))
\r
29 return nextMatch(pos+imax,p);
\r
31 Pattern clone1(Hashtable h) { return new BackMatch(id); }
\r