public class Replace
extends java.lang.Object
Replace
class implements the string replacement
functionality formerly coded in the base/base_replace.c
C
file. This class acts as a data container for the concrete replacement
definition and also does the actual replacement for the String/UString ECMA
host object and also for Java clients.
The usage of this class is relatively simple :
addPattern(String, String)
,
addPattern(int, String, String)
or addPatterns(String[][])
calls
replace(String, int)
for each string you want to work on
The flags for the replacement are defined as follows :
REPLACE_IGNORE_HTML
REPLACE_WHOLE_WORD
The replacement algorithm works in three steps :
Modifier and Type | Field and Description |
---|---|
static int |
REPLACE_IGNORE_HTML
Replacement flag to ignore any strings occuring within HTML tags
|
static int |
REPLACE_NONE
Replacment flag indicating no special treatment
|
static int |
REPLACE_WHOLE_WORD
Replacement flag to only replace search words occuring as stand- alone
words
|
Constructor and Description |
---|
Replace()
Default constructor for the replacement object
|
Modifier and Type | Method and Description |
---|---|
void |
addPattern(int pos,
java.lang.String pattern,
java.lang.String replacement)
Insert the pattern at the indicated position in the internal pattern list
|
void |
addPattern(java.lang.String pattern,
java.lang.String replacement)
Append the pattern to the internal pattern list
|
void |
addPatterns(java.lang.String[][] prPairs)
Append all the pattern/replacement String pairs to the list.
|
int |
getFlags()
Returns the current flags
|
java.util.Iterator |
getPatterns()
Returns an iterator over the existing patterns
|
java.lang.String |
replace(java.lang.String source)
calls
replace(String, int) with wref=0 |
java.lang.String |
replace(java.lang.String source,
int wref)
The real replacement of the patterns within the input takes place here.
|
void |
setFlags(int flags)
Set the indicated replacement flags
|
public static final int REPLACE_NONE
public static final int REPLACE_IGNORE_HTML
public static final int REPLACE_WHOLE_WORD
public java.lang.String replace(java.lang.String source)
replace(String, int)
with wref=0public java.lang.String replace(java.lang.String source, int wref)
source
- The String to do the work inwref
- Reference weight (?)public void setFlags(int flags)
flags
- The flags to setpublic int getFlags()
public void addPattern(int pos, java.lang.String pattern, java.lang.String replacement)
pos
- The position to insert the pattern atpattern
- The pattern String for the new patternreplacement
- The replacement String for the new patternpublic void addPattern(java.lang.String pattern, java.lang.String replacement)
pattern
- The pattern String for the new patternreplacement
- The replacement String for the new patternpublic void addPatterns(java.lang.String[][] prPairs)
prPairs
- An Array of pattern/replacement String pairs.public java.util.Iterator getPatterns()
Copyright © 2010 - 2020 Adobe. All Rights Reserved