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
10 /** This method implements the pattern elements $1, $2, etc in
\r
11 a substitution rule. The apply(StringBufferLike sb,RegRes rr) method of this ReplaceRule
\r
12 simply appends the contents of rr.stringMatched(n), where n is
\r
13 the integer supplied to the constructor. */
\r
14 public class BackRefRule extends ReplaceRule {
\r
16 public BackRefRule(int n) { this.n = n; }
\r
17 public void apply(StringBufferLike sb,RegRes res) {
\r
18 String x = res.stringMatched(n);
\r
19 sb.append(x == null ? "" : x);
\r
21 public String toString1() { return "$"+n; }
\r
22 public Object clone1() { return new BackRefRule(n); }
\r