public class Printf extends AbstractFaAction
implements an FaAction
to apply a PrintfFormatter
to the matched text. If a MapProvider
is
found in the DfaRun.clientData
field of the
calling DfaRun
, this is passed on to the
Formatter
's format()
method
to allow for "%(key)
" expansions. To store values
in the Map
, use Store
.
format strings
,
Serialized FormConstructor and Description |
---|
Printf(boolean useSubmatches,
java.lang.String format)
create an
FaAction to format a match according to
the given format string. |
Printf(java.lang.String format)
creates an
FaAction to format a match according to
the given format string. |
Printf(TextSplitter sp,
Formatter fmt,
int prio)
creates an
FaAction to format the matching text
according to a Formatter . |
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. |
java.lang.String |
toString() |
mergeWith, setPriority
public Printf(TextSplitter sp, Formatter fmt, int prio)
creates an FaAction
to format the matching text
according to a Formatter
.
sp
- is applied to the match to separate it into parts. This
may be null
to indicate that submatches should be
used. Another useful special case is covered by TextSplitter.NULLSPLITTER
.fmt
- is the Formatter
to use to format the
match. The most common implementation is the PrintfFormatter
.format strings
public Printf(boolean useSubmatches, java.lang.String format) throws ReSyntaxException
create an FaAction
to format a match according to
the given format string.
useSubmatches
- if true
, the formatter will
have access to submatches recorded during the match. If
false
only the format control "%0" is allowed and
refers to the whole match.format
- is used to create a PrintfFormatter
.ReSyntaxException
public Printf(java.lang.String format) throws ReSyntaxException
creates an FaAction
to format a match according to
the given format string. This is a shortcut for Printf(false, format, 0)
.
ReSyntaxException
public void invoke(java.lang.StringBuilder out, int start, DfaRun runner) throws CallbackException
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
.
CallbackException
public java.lang.String toString()
toString
in class java.lang.Object