Class PerlSubstitution

All Implemented Interfaces:

public class PerlSubstitution
extends java.lang.Object
implements Substitution

An implementation of the Substitution interface. Performs substitutions in accordance with Perl-like substitution scripts.
The latter is a string, containing a mix of memory register references and plain text blocks.
It may look like "some_chars $1 some_chars$2some_chars" or "123${1}45${2}67".
A tag consisting of '$',not preceeded by the escape character'\' and followed by some digits (possibly enclosed in the curled brackets) is interpreted as a memory register reference, the digits forming a register ID. All the rest is considered as a plain text.
Upon the Replacer has found a text block that matches the pattern, a references in a replacement string are replaced by the contents of corresponding memory registers, and the resulting text replaces the matched block.
For example, the following code:

    new Replacer(new Pattern("\\b(\\d+)\\b"),new PerlSubstitution("'$1'")).replace("abc 123 def")
will print "abc '123' def".

See Also:
Substitution, Replacer, Pattern

Constructor Summary
PerlSubstitution(java.lang.String s)
Method Summary
 void appendSubstitution(MatchResult match, TextBuffer dest)
 java.lang.String toString()
 java.lang.String value(MatchResult mr)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public PerlSubstitution(java.lang.String s)
Method Detail


public java.lang.String value(MatchResult mr)


public void appendSubstitution(MatchResult match,
                               TextBuffer dest)
Specified by:
appendSubstitution in interface Substitution


public java.lang.String toString()
toString in class java.lang.Object