JAL-1807 still testing
[jalviewjs.git] / unused / com / stevesoft / pat / BackRefRule.java
1 //\r
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
5 // the details.\r
6 //    -- Happy Computing!\r
7 //\r
8 package com.stevesoft.pat;\r
9 \r
10 /**\r
11  * This method implements the pattern elements $1, $2, etc in a substitution\r
12  * rule. The apply(StringBufferLike sb,RegRes rr) method of this ReplaceRule\r
13  * simply appends the contents of rr.stringMatched(n), where n is the integer\r
14  * supplied to the constructor.\r
15  */\r
16 public class BackRefRule extends ReplaceRule\r
17 {\r
18   int n;\r
19 \r
20   public BackRefRule(int n)\r
21   {\r
22     this.n = n;\r
23   }\r
24 \r
25   public void apply(StringBufferLike sb, RegRes res)\r
26   {\r
27     String x = res.stringMatched(n);\r
28     sb.appendStr(x == null ? "" : x);\r
29   }\r
30 \r
31   public String toString1()\r
32   {\r
33     return "$" + n;\r
34   }\r
35 \r
36   public Object clone1()\r
37   {\r
38     return new BackRefRule(n);\r
39   }\r
40 }\r