Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD


Class COM.stevesoft.pat.Transformer

java.lang.Object
  |
  +--COM.stevesoft.pat.Transformer

public class Transformer
extends java.lang.Object

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 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 replaceAll(java.lang.String s)
          Replace all matches in the current String.
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.
java.lang.String replaceFirst(java.lang.String s)
          Replace the first matching pattern in String s.
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, notifyAll, notify, toString, wait, wait, wait

 

Constructor Detail

Transformer

public Transformer(boolean auto)
Instantiate a new Transformer object.
Method Detail

getReplacer

public Replacer getReplacer()
Get a replacer to that works with the current Regex.
See Also:
Replacer

add

public void add(Regex r)
Add a new Regex to the set of Regex's.

patterns

public int patterns()
Returns the number of Regex's in this Transformer.

getRegexAt

public Regex getRegexAt(int i)
Get the Regex at position i in this Transformer.

setRegexAt

public void setRegexAt(Regex rx,
                       int i)
Set the Regex at position i in this Transformer.

add

public void add(java.lang.String rs)
Add a new Regex by calling Regex.perlCode
See Also:
perlCode(java.lang.String)

add

public void add(java.lang.String[] array)
Add an array of Strings (which will be converted to Regex's via the Regex.perlCode method.
See Also:
perlCode(java.lang.String)

replaceAll

public java.lang.String replaceAll(java.lang.String s)
Replace all matches in the current String.

replaceAllFrom

public java.lang.String replaceAllFrom(java.lang.String s,
                             int start)
Replace all matching patterns beginning at position start.

replaceAllRegion

public java.lang.String replaceAllRegion(java.lang.String s,
                               int start,
                               int end)
Replace all matching patterns beginning between the positions start and end inclusive.

replaceFirst

public java.lang.String replaceFirst(java.lang.String s)
Replace the first matching pattern in String s.

replaceFirstFrom

public java.lang.String replaceFirstFrom(java.lang.String s,
                               int start)
Replace the first matching pattern after position start in String s.

replaceFirstRegion

public java.lang.String replaceFirstRegion(java.lang.String s,
                                 int start,
                                 int end)
Replace the first matching pattern that begins between start and end inclusive.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD