Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
BackRefRule | 16 | 5 | 5 |
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 | 0 | public BackRefRule(int n) |
21 | { | |
22 | 0 | this.n = n; |
23 | } | |
24 | ||
25 | 0 | public void apply(StringBufferLike sb, RegRes res) |
26 | { | |
27 | 0 | String x = res.stringMatched(n); |
28 | 0 | sb.append(x == null ? "" : x); |
29 | } | |
30 | ||
31 | 0 | public String toString1() |
32 | { | |
33 | 0 | return "$" + n; |
34 | } | |
35 | ||
36 | 0 | public Object clone1() |
37 | { | |
38 | 0 | return new BackRefRule(n); |
39 | } | |
40 | } |