needed for applet search
[jalview.git] / src / com / stevesoft / pat / BackRefRule.java
diff --git a/src/com/stevesoft/pat/BackRefRule.java b/src/com/stevesoft/pat/BackRefRule.java
new file mode 100755 (executable)
index 0000000..64a5d6e
--- /dev/null
@@ -0,0 +1,23 @@
+//\r
+// This software is now distributed according to\r
+// the Lesser Gnu Public License.  Please see\r
+// http://www.gnu.org/copyleft/lesser.txt for\r
+// the details.\r
+//    -- Happy Computing!\r
+//\r
+package com.stevesoft.pat;\r
+\r
+/** This method implements the pattern elements $1, $2, etc in\r
+    a substitution rule. The apply(StringBufferLike sb,RegRes rr) method of this ReplaceRule\r
+    simply appends the contents of rr.stringMatched(n), where n is\r
+    the integer supplied to the constructor. */\r
+public class BackRefRule extends ReplaceRule {\r
+    int n;\r
+    public BackRefRule(int n) { this.n = n; }\r
+    public void apply(StringBufferLike sb,RegRes res) {\r
+        String x = res.stringMatched(n);\r
+        sb.append(x == null ? "" : x);\r
+    }\r
+    public String toString1() { return "$"+n; }\r
+    public Object clone1() { return new BackRefRule(n); }\r
+}\r