Package totalcross.util.regex
Class PerlSubstitution
- java.lang.Object
-
- totalcross.util.regex.PerlSubstitution
-
- All Implemented Interfaces:
Substitution
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:System.out.println("\""+ 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
Constructors Constructor Description PerlSubstitution(java.lang.String s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendSubstitution(MatchResult match, TextBuffer dest)java.lang.StringtoString()java.lang.Stringvalue(MatchResult mr)
-
-
-
Method Detail
-
value
public java.lang.String value(MatchResult mr)
-
appendSubstitution
public void appendSubstitution(MatchResult match, TextBuffer dest)
- Specified by:
appendSubstitutionin interfaceSubstitution
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-