com.stevesoft.pat
Class ReplaceRule
java.lang.Object
|
+--com.stevesoft.pat.ReplaceRule
- Direct Known Subclasses:
- AmpersandRule, BackRefRule, LeftRule, NullRule, RightRule, SpecialRule, StringRule
- public abstract class ReplaceRule
- extends java.lang.Object
ReplaceRule is a singly linked list of Objects which describe how
to replace the matched portion of a String. The only member method
that you absolutely need to define to use this class is apply(StringBuffer,RegRes) --
although you may want define toString1() and clone1() (if you are
unhappy with the default methods) that are needed by
the clone() or toString() methods on this class.
During the replacement process, each ReplaceRule tells the replacer
what to add to StringBuffer and uses the contents of the Regular
expression result to get the information it needs to
do this. Here is an example
- See Also:
NullRule,
AmpersandRule,
BackRefRule,
LeftRule,
RightRule,
StringRule
|
Field Summary |
protected ReplaceRule |
next
points to the next ReplaceRule in the linked list. |
|
Method Summary |
ReplaceRule |
add(ReplaceRule adding)
|
void |
addRule(ReplaceRule r)
Add another ReplaceRule to the linked list. |
abstract void |
apply(StringBufferLike sb,
RegRes r)
This function appends to the StringBufferLike the text you want
to replaced the portion of the String last matched. |
ReplaceRule |
arg(java.lang.String s)
Modified the behavior of a ReplaceRule by supplying
an argument. |
java.lang.Object |
clone()
|
java.lang.Object |
clone1()
A rule describing how to clone only the current ReplaceRule,
and none of the others in this linked list. |
static void |
define(java.lang.String s,
Regex r)
|
static void |
define(java.lang.String s,
ReplaceRule r)
|
static void |
define(java.lang.String s,
Transformer t)
|
static boolean |
isDefined(java.lang.String s)
|
static ReplaceRule |
perlCode(java.lang.String s)
Compile a ReplaceRule using the text that would go between
the second and third /'s in a typical substitution pattern
in Perl: s/ ... |
java.lang.String |
toString()
Convert to a String. |
java.lang.String |
toString1()
This tells how to convert just the current element (and none
of the other items in the linked list) to a String. |
static void |
undefine(java.lang.String s)
|
| Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
next
protected ReplaceRule next
- points to the next ReplaceRule in the linked list.
ReplaceRule
public ReplaceRule()
apply
public abstract void apply(StringBufferLike sb,
RegRes r)
- This function appends to the StringBufferLike the text you want
to replaced the portion of the String last matched.
clone1
public java.lang.Object clone1()
- A rule describing how to clone only the current ReplaceRule,
and none of the others in this linked list. It is called by
clone() for each item in the list.
clone
public final java.lang.Object clone()
- Overrides:
- clone in class java.lang.Object
add
public ReplaceRule add(ReplaceRule adding)
addRule
public void addRule(ReplaceRule r)
- Add another ReplaceRule to the linked list.
perlCode
public static ReplaceRule perlCode(java.lang.String s)
- Compile a ReplaceRule using the text that would go between
the second and third /'s in a typical substitution pattern
in Perl: s/ ... / The argument to ReplaceRule.perlCode /.
isDefined
public static boolean isDefined(java.lang.String s)
define
public static void define(java.lang.String s,
Regex r)
define
public static void define(java.lang.String s,
ReplaceRule r)
define
public static void define(java.lang.String s,
Transformer t)
undefine
public static void undefine(java.lang.String s)
toString1
public java.lang.String toString1()
- This tells how to convert just the current element (and none
of the other items in the linked list) to a String. This
method is called by toString() for each item in the linked
list.
toString
public final java.lang.String toString()
- Convert to a String.
- Overrides:
- toString in class java.lang.Object
arg
public ReplaceRule arg(java.lang.String s)
- Modified the behavior of a ReplaceRule by supplying
an argument. If a ReplaceRule named "foo" is defined
and the pattern "s/x/${foo:5}/" is given to Regex.perlCode,
then the "foo" the definition of "foo" will be retrieved
and arg("5") will be called. If the result is non-null,
that is the ReplaceRule that will be used. If the result
is null, then the pattern works just as if it were
"s/x/${foo}/".
- See Also:
Validator.arg(java.lang.String)