public class SearchReplace extends AbstractFaAction
implements an FaAction
which scans the matched text for a
given regular expression and replaces those matches by applying a
PrintfFormatter
.
Constructor and Description |
---|
SearchReplace(java.lang.String regexp,
java.lang.String format)
calls the four parameter constructor with
sp=null and
count==-1 . |
SearchReplace(java.lang.String regexp,
java.lang.String format,
int count)
calls the four parameter constructor with
sp==null . |
SearchReplace(java.lang.String regexp,
TextSplitter sp,
Formatter fmt,
int count)
creates an action to search and replace within a match.
|
Modifier and Type | Method and Description |
---|---|
void |
invoke(java.lang.StringBuilder out,
int start,
DfaRun runner)
is called by methods of
DfaRun in case of a
match. |
mergeWith, setPriority
public SearchReplace(java.lang.String regexp, TextSplitter sp, Formatter fmt, int count) throws ReSyntaxException, CompileDfaException
creates an action to search and replace within a match. Within
the match, regexp
is sought consecutively up to
count
times. If sp
is not
null
, it is applied to
separate the text matching regexp
into
parts. Otherwise the reported submatches regexp
are
used by fmt
to rewrite the text matched by
regexp
.
sp
- may be null in which case submatches of
regexp
are used as the parts.count
- is the number of replacements to make. If
count
is negative, up to 232 matches
(i.e. all) are replaced.ReSyntaxException
CompileDfaException
format string
public SearchReplace(java.lang.String regexp, java.lang.String format) throws ReSyntaxException, CompileDfaException
calls the four parameter constructor with sp=null
and
count==-1
.
ReSyntaxException
CompileDfaException
public SearchReplace(java.lang.String regexp, java.lang.String format, int count) throws ReSyntaxException, CompileDfaException
sp==null
.ReSyntaxException
CompileDfaException
public void invoke(java.lang.StringBuilder out, int start, DfaRun runner)
FaAction
is called by methods of DfaRun
in case of a
match. Parameter yytext
contains the matching text
from position start
onwards. The callback may change
the whole of yytext
, but the under most
circumstances, only the matching text should be
changed. Parameter runner
is the DfaRun
object which called this function. Of interest are its fields
DfaRun.clientData
and DfaRun.collect
.