|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.stevesoft.pat.Transformer
Sometimes you want to replace a whole bunch of things that might occur within a single line of text. One efficient way to do this, both in terms of performance and programming ease, is with Transformer. The Transformer contains an array of Regex's and uses the Regex that matches earliest within the text to do the replacing, if two Regex's match at the same time it uses the one put in the Transformer first.
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 Summary | |
Transformer(boolean auto)
Instantiate a new Transformer object. |
|
| Method Summary | |
void |
add(Regex r)
Add a new Regex to the set of Regex's. |
void |
add(java.lang.String rs)
Add a new Regex by calling Regex.perlCode |
void |
add(java.lang.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. |
java.lang.String |
replaceAll(java.lang.String s)
Replace all matches in the current String. |
StringLike |
replaceAll(StringLike s)
|
java.lang.String |
replaceAllFrom(java.lang.String s,
int start)
Replace all matching patterns beginning at position start. |
java.lang.String |
replaceAllRegion(java.lang.String s,
int start,
int end)
Replace all matching patterns beginning between the positions start and end inclusive. |
java.lang.String |
replaceFirst(java.lang.String s)
Replace the first matching pattern in String s. |
java.lang.String |
replaceFirstFrom(java.lang.String s,
int start)
Replace the first matching pattern after position start in String s. |
java.lang.String |
replaceFirstRegion(java.lang.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. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public Transformer(boolean auto)
| Method Detail |
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(java.lang.String rs)
Regex.perlCode(java.lang.String)public void add(java.lang.String[] array)
Regex.perlCode(java.lang.String)public java.lang.String replaceAll(java.lang.String s)
public StringLike replaceAll(StringLike s)
public java.lang.String replaceAllFrom(java.lang.String s,
int start)
public java.lang.String replaceAllRegion(java.lang.String s,
int start,
int end)
public java.lang.String replaceFirst(java.lang.String s)
public java.lang.String replaceFirstFrom(java.lang.String s,
int start)
public java.lang.String replaceFirstRegion(java.lang.String s,
int start,
int end)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||