com.stevesoft.pat
Class Replacer

java.lang.Object
  |
  +--com.stevesoft.pat.Replacer

public class Replacer
extends java.lang.Object

To use this class, first use either the getReplacer() method from Transformer or Regex. You can then use replaceAll, replaceFirst, etc. methods on the Replacer in the same way that you can from either of those two classes.

The only potential difference between using the methods of Replacer to do the replacing is that Replacer remembers changes to the replacing object between calls to replaceAll, replaceFirst etc. For details, see the example file trans3.java.

See Also:
Transformer, Regex

Constructor Summary
Replacer()
          Instantiate a new Replacer.
 
Method Summary
 void apply(Regex r)
          Another form of apply, it is the same as apply(r,r.getReplaceRule()).
 void apply(RegRes r, ReplaceRule rp)
          This method allows you to apply the results of several matches in a sequence to modify a String of text.
 void apply1(RegRes rr)
           
 java.lang.Object clone()
           
 StringLike finish()
          This finishes the replacement, appending the right() part of the last RegRes given to substitute(RegRes).
 Regex getRegex()
           
 boolean isSpecial(ReplaceRule x)
           
 int lastMatchedTo()
           
 java.lang.String replaceAll(java.lang.String s)
           
 StringLike replaceAll(StringLike s)
           
 java.lang.String replaceAllFrom(java.lang.String s, int start)
           
 StringLike replaceAllFrom(StringLike s, int start)
           
 java.lang.String replaceAllRegion(java.lang.String s, int start, int end)
           
 StringLike replaceAllRegion(StringLike s, int start, int end)
           
 StringLike replaceAllRegion(StringLike s, Regex r, int start, int end)
          This method replaces all occurences of the Regex in the String starting with postition pos according to the Replacer rule of this object.
 StringLike replaceAllRegion(java.lang.String s, Regex r, int start, int end)
           
 StringLike replaceFirst(StringLike s)
           
 StringLike replaceFirstFrom(StringLike s, int start)
           
 StringLike replaceFirstRegion(StringLike s, int start, int end)
           
 StringLike replaceFirstRegion(StringLike s, Regex r, int start, int end)
          This method replaces the first occurence of the Regex in the String starting with position pos according to the Replacer rule of this object.
 StringLike replaceFirstRegion(java.lang.String s, Regex r, int start, int end)
           
 void setBuffer(StringBufferLike sbl)
           
 void setPos(int pos)
           
 void setSource(StringLike sl)
           
 boolean WantMoreText()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Replacer

public Replacer()
Instantiate a new Replacer.
Method Detail

replaceFirstRegion

public StringLike replaceFirstRegion(java.lang.String s,
                                     Regex r,
                                     int start,
                                     int end)

replaceFirstRegion

public StringLike replaceFirstRegion(StringLike s,
                                     Regex r,
                                     int start,
                                     int end)
This method replaces the first occurence of the Regex in the String starting with position pos according to the Replacer rule of this object.

replaceFirst

public StringLike replaceFirst(StringLike s)

replaceFirstFrom

public StringLike replaceFirstFrom(StringLike s,
                                   int start)

replaceFirstRegion

public StringLike replaceFirstRegion(StringLike s,
                                     int start,
                                     int end)

replaceAllRegion

public StringLike replaceAllRegion(java.lang.String s,
                                   Regex r,
                                   int start,
                                   int end)

replaceAllRegion

public StringLike replaceAllRegion(StringLike s,
                                   Regex r,
                                   int start,
                                   int end)
This method replaces all occurences of the Regex in the String starting with postition pos according to the Replacer rule of this object.

replaceAll

public StringLike replaceAll(StringLike s)

replaceAllFrom

public StringLike replaceAllFrom(StringLike s,
                                 int start)

replaceAllRegion

public StringLike replaceAllRegion(StringLike s,
                                   int start,
                                   int end)

replaceAll

public java.lang.String replaceAll(java.lang.String s)

replaceAllFrom

public java.lang.String replaceAllFrom(java.lang.String s,
                                       int start)

replaceAllRegion

public java.lang.String replaceAllRegion(java.lang.String s,
                                         int start,
                                         int end)

isSpecial

public final boolean isSpecial(ReplaceRule x)

apply1

public final void apply1(RegRes rr)

apply

public void apply(RegRes r,
                  ReplaceRule rp)
This method allows you to apply the results of several matches in a sequence to modify a String of text. Each call in the sequence must operate on the same piece of text and the matchedFrom() of each RegRes given to this method must be greater in value than the preceeding RegRes's matchedTo() value.

WantMoreText

public boolean WantMoreText()

apply

public void apply(Regex r)
Another form of apply, it is the same as apply(r,r.getReplaceRule()).

finish

public StringLike finish()
This finishes the replacement, appending the right() part of the last RegRes given to substitute(RegRes). After this method is called, the Replace object is reset to perform another substitution. If no RegRes objects with a true didMatch are applied, this returns null.

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

lastMatchedTo

public int lastMatchedTo()

getRegex

public Regex getRegex()

setSource

public void setSource(StringLike sl)

setBuffer

public void setBuffer(StringBufferLike sbl)

setPos

public void setPos(int pos)