public class Replacer
extends java.lang.Object
Pattern p=new Pattern("\\w+"); Replacer perlExpressionReplacer=p.replacer("[$&]"); //or another way to do the same Substitution myOwnModel=new Substitution(){ public void appendSubstitution(MatchResult match,TextBuffer tb){ tb.append('['); match.getGroup(MatchResult.MATCH,tb); tb.append(']'); } } Replacer myVeryOwnReplacer=new Replacer(p,myOwnModel);The second method is much more verbose, but gives more freedom. To perform a replacement call replace(someInput):
System.out.print(perlExpressionReplacer.replace("All your base ")); System.out.println(myVeryOwnReplacer.replace("are belong to us")); //result: "[All] [your] [base] [are] [belong] [to] [us]"
Constructor and Description |
---|
Replacer(Pattern pattern,
java.lang.String substitution) |
Replacer(Pattern pattern,
java.lang.String substitution,
boolean isPerlExpr) |
Replacer(Pattern pattern,
Substitution substitution) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
replace(char[] chars,
int off,
int len) |
void |
replace(char[] chars,
int off,
int len,
CharStream out) |
int |
replace(char[] chars,
int off,
int len,
java.lang.StringBuffer sb) |
int |
replace(char[] chars,
int off,
int len,
TextBuffer dest) |
java.lang.String |
replace(CharStream text,
int length) |
void |
replace(CharStream in,
int length,
CharStream out) |
int |
replace(CharStream text,
int length,
java.lang.StringBuffer sb) |
int |
replace(CharStream text,
int length,
TextBuffer dest) |
static int |
replace(Matcher m,
Substitution substitution,
CharStream out) |
static int |
replace(Matcher m,
Substitution substitution,
TextBuffer dest)
Replaces all occurences of a matcher's pattern in a matcher's target
by a given substitution appending the result to a buffer.
The substitution starts from current matcher's position, current match not included. |
java.lang.String |
replace(MatchResult res,
int group) |
void |
replace(MatchResult res,
int group,
CharStream out) |
int |
replace(MatchResult res,
int group,
java.lang.StringBuffer sb) |
int |
replace(MatchResult res,
int group,
TextBuffer dest) |
void |
replace(MatchResult res,
java.lang.String groupName,
CharStream out) |
int |
replace(MatchResult res,
java.lang.String groupName,
java.lang.StringBuffer sb) |
int |
replace(MatchResult res,
java.lang.String groupName,
TextBuffer dest) |
java.lang.String |
replace(java.lang.String text) |
void |
replace(java.lang.String text,
CharStream out) |
int |
replace(java.lang.String text,
java.lang.StringBuffer sb) |
int |
replace(java.lang.String text,
TextBuffer dest) |
void |
setSubstitution(java.lang.String s,
boolean isPerlExpr) |
static TextBuffer |
wrap(CharStream writer) |
static TextBuffer |
wrap(java.lang.StringBuffer sb) |
public Replacer(Pattern pattern, Substitution substitution)
public Replacer(Pattern pattern, java.lang.String substitution)
public Replacer(Pattern pattern, java.lang.String substitution, boolean isPerlExpr)
public void setSubstitution(java.lang.String s, boolean isPerlExpr)
public java.lang.String replace(java.lang.String text)
public java.lang.String replace(char[] chars, int off, int len)
public java.lang.String replace(MatchResult res, int group)
public java.lang.String replace(CharStream text, int length) throws IOException
IOException
public int replace(java.lang.String text, java.lang.StringBuffer sb)
public int replace(char[] chars, int off, int len, java.lang.StringBuffer sb)
public int replace(MatchResult res, int group, java.lang.StringBuffer sb)
public int replace(MatchResult res, java.lang.String groupName, java.lang.StringBuffer sb)
public int replace(CharStream text, int length, java.lang.StringBuffer sb) throws IOException
IOException
public int replace(java.lang.String text, TextBuffer dest)
public int replace(char[] chars, int off, int len, TextBuffer dest)
public int replace(MatchResult res, int group, TextBuffer dest)
public int replace(MatchResult res, java.lang.String groupName, TextBuffer dest)
public int replace(CharStream text, int length, TextBuffer dest) throws IOException
IOException
public static int replace(Matcher m, Substitution substitution, TextBuffer dest)
public static int replace(Matcher m, Substitution substitution, CharStream out) throws IOException
IOException
public void replace(java.lang.String text, CharStream out) throws IOException
IOException
public void replace(char[] chars, int off, int len, CharStream out) throws IOException
IOException
public void replace(MatchResult res, int group, CharStream out) throws IOException
IOException
public void replace(MatchResult res, java.lang.String groupName, CharStream out) throws IOException
IOException
public void replace(CharStream in, int length, CharStream out) throws IOException
IOException
public static TextBuffer wrap(java.lang.StringBuffer sb)
public static TextBuffer wrap(CharStream writer)