JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / BackRefRule.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat;
9
10 /**
11  * This method implements the pattern elements $1, $2, etc in a substitution
12  * rule. The apply(StringBufferLike sb,RegRes rr) method of this ReplaceRule
13  * simply appends the contents of rr.stringMatched(n), where n is the integer
14  * supplied to the constructor.
15  */
16 public class BackRefRule extends ReplaceRule
17 {
18   int n;
19
20   public BackRefRule(int n)
21   {
22     this.n = n;
23   }
24
25   public void apply(StringBufferLike sb, RegRes res)
26   {
27     String x = res.stringMatched(n);
28     sb.appendStr(x == null ? "" : x);
29   }
30
31   public String toString1()
32   {
33     return "$" + n;
34   }
35
36   public Object clone1()
37   {
38     return new BackRefRule(n);
39   }
40 }