public class Transformer extends Object
This feature can be used to prevent transformations from occurring in certain regions. For example, if I add the rule s'//.*'$&' and then add the rule s/hello/goodbye/ the Transformer will replace "hello" with "goodbye" except when it occurs inside a double-slash style of comment. The transformation on the comment goes first, does nothing, and precludes transformation on the same region of text as the s/hello/goodbye/ rule.
So far, at least, this class does not have the capability of turning into a giant robot :-)
| Constructor and Description |
|---|
Transformer(boolean auto)
Instantiate a new Transformer object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Regex r)
Add a new Regex to the set of Regex's.
|
void |
add(String rs)
Add a new Regex by calling Regex.perlCode
|
void |
add(String[] array)
Add an array of Strings (which will be converted to
Regex's via the Regex.perlCode method.
|
Regex |
getRegexAt(int i)
Get the Regex at position i in this Transformer.
|
Replacer |
getReplacer()
Get a replacer to that works with the current Regex.
|
int |
patterns()
Returns the number of Regex's in this Transformer.
|
String |
replaceAll(String s)
Replace all matches in the current String.
|
StringLike |
replaceAll(StringLike s) |
String |
replaceAllFrom(String s,
int start)
Replace all matching patterns beginning at position start.
|
String |
replaceAllRegion(String s,
int start,
int end)
Replace all matching patterns beginning between the positions
start and end inclusive.
|
String |
replaceFirst(String s)
Replace the first matching pattern in String s.
|
String |
replaceFirstFrom(String s,
int start)
Replace the first matching pattern after position start in
String s.
|
String |
replaceFirstRegion(String s,
int start,
int end)
Replace the first matching pattern that begins between
start and end inclusive.
|
void |
setRegexAt(Regex rx,
int i)
Set the Regex at position i in this Transformer.
|
public Transformer(boolean auto)
public Replacer getReplacer()
Replacerpublic void add(Regex r)
public int patterns()
public Regex getRegexAt(int i)
public void setRegexAt(Regex rx, int i)
public void add(String rs)
Regex.perlCode(java.lang.String)public void add(String[] array)
Regex.perlCode(java.lang.String)public StringLike replaceAll(StringLike s)
public String replaceAllFrom(String s, int start)
public String replaceAllRegion(String s, int start, int end)
public String replaceFirstFrom(String s, int start)