Modifier and Type | Field and Description |
---|---|
static Function<Matcher,String> |
SYSTEM_PROPERTY_MATCH_REPLACER
A match replacer which returns the value of the system property named by group #1 of the match.
|
Modifier and Type | Method and Description |
---|---|
static Function<Matcher,String> |
constantMatchReplacer(String string)
Returns a match replacer which always returns the given string.
|
static Function<Matcher,String> |
constantReplacer(String string)
Deprecated.
Use
constantMatchReplacer(String) instead |
static long |
replaceAll(Reader in,
Pattern pattern,
String replacementString,
Appendable out)
Reads text from in, replaces all matches of pattern according to the
replacementString, and writes the result to out.
|
static Reader |
replaceAllFilterReader(Reader delegate,
Pattern pattern,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends IOException> matchReplacer)
Creates and returns a filter
Reader which replaces matches of the pattern within the
character stream on-the-fly through the matchReplacer. |
static Writer |
replaceAllFilterWriter(Pattern pattern,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends IOException> matchReplacer,
Appendable delegate)
Creates and returns a filter
Writer which replaces matches of the pattern within the
character stream on-the-fly through the matchReplacer. |
static <EX extends Throwable> |
replacementStringMatchReplacer(String replacementString) |
static <EX extends Throwable> |
replacementStringReplacer(String replacementString)
Deprecated.
Use
replacementStringMatchReplacer(String) instead |
static <EX extends Throwable> |
replaceSome(Matcher matcher,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer)
The generalized form of
Matcher.replaceAll(String) : The replacement for a match is not formed from a
"replacement string" (with variables "$0", "$1", ...), but is computed by the matchReplacer. |
static <EX extends Throwable> |
replaceSome(Reader in,
Pattern pattern,
FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer,
Appendable out,
int bufferCapacity)
Reads characters from in, finds all matches of pattern, replaces each match with the
result of the matchReplacer, and writes the result to out.
|
static long |
replaceSystemProperties(Reader in,
Appendable out)
Reads text from in, replaces all matches of
"
${ system-property-name} " with the value of the system property, and writes
the result to out. |
static <EX extends Throwable> |
substitutor(Pattern pattern,
String replacementString)
Creates and returns a
Substitutor which replaces Pattern matches in a stream of strings through
the replacementString. |
static Function<Matcher,String> |
systemPropertyReplacer()
Deprecated.
Use
SYSTEM_PROPERTY_MATCH_REPLACER instead |
public static final Function<Matcher,String> SYSTEM_PROPERTY_MATCH_REPLACER
Example:
PatternUtil.replaceAll( Pattern.compile("\\$\\{([^}]+)}").matcher("file.separator is ${file.separator}"), PatternUtil.SYSTEM_PROPERTY_MATCH_REPLACER )
@Deprecated public static Function<Matcher,String> constantReplacer(@Nullable String string)
constantMatchReplacer(String)
insteadpublic static Function<Matcher,String> constantMatchReplacer(@Nullable String string)
Opposed to replacementStringMatchReplacer(String)
, "$
" and "\
" have no special
meaning.
@Deprecated public static <EX extends Throwable> FunctionWhichThrows<Matcher,String,? extends EX> replacementStringReplacer(String replacementString)
replacementStringMatchReplacer(String)
insteadpublic static <EX extends Throwable> FunctionWhichThrows<Matcher,String,? extends EX> replacementStringMatchReplacer(String replacementString)
replacementString
- See Matcher.appendReplacement(StringBuffer, String)
constantMatchReplacer(String)
,
SYSTEM_PROPERTY_MATCH_REPLACER
@Deprecated public static Function<Matcher,String> systemPropertyReplacer()
SYSTEM_PROPERTY_MATCH_REPLACER
insteadpublic static long replaceAll(Reader in, Pattern pattern, String replacementString, Appendable out) throws IOException
The pattern search is stream-oriented, not line-oriented, i.e. matches are found even across line boundaries.
Thus the pattern should have been compiled with the Pattern.MULTILINE
flag.
IOException
For the format of the replacementString
public static long replaceSystemProperties(Reader in, Appendable out) throws IOException
${
system-property-name}
" with the value of the system property, and writes
the result to out.IOException
public static <EX extends Throwable> String replaceSome(Matcher matcher, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer) throws EX extends Throwable
Matcher.replaceAll(String)
: The replacement for a match is not formed from a
"replacement string" (with variables "$0", "$1", ...), but is computed by the matchReplacer. If the
matchReplacer returns null
for a match, then the match is not replaced.EX extends Throwable
public static <EX extends Throwable> int replaceSome(Reader in, Pattern pattern, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends EX> matchReplacer, Appendable out, int bufferCapacity) throws IOException, EX extends Throwable
null
for a match, then the match is not replaced.
The pattern search is stream-oriented, not line-oriented, i.e. matches are found even across line boundaries.
Therefore the pattern should have been compiled with the Pattern.MULTILINE
flag.
This method attempts to load as few characters into memory as possible. Notice, however, that in particular
the usage of "greedy quantifiers", for example "a.*b
", can lead to all the remaining content being
read into memory.
bufferCapacity
- The number of chars that are read repeatedly, until end-of-input, from inIOException
EX extends Throwable
public static Reader replaceAllFilterReader(Reader delegate, Pattern pattern, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends IOException> matchReplacer)
Reader
which replaces matches of the pattern within the
character stream on-the-fly through the matchReplacer.public static Writer replaceAllFilterWriter(Pattern pattern, FunctionWhichThrows<? super Matcher,? extends CharSequence,? extends IOException> matchReplacer, Appendable delegate)
Writer
which replaces matches of the pattern within the
character stream on-the-fly through the matchReplacer.public static <EX extends Throwable> Substitutor<EX> substitutor(Pattern pattern, String replacementString)
Substitutor
which replaces Pattern
matches in a stream of strings through
the replacementString.
As the returned transformer consumes a sequence of strings, it produces a sequence of strings, and the concatenation of the consumed strings equals the concatenation of the produced strings, except that all matches of the pattern are substituted with the replacementString.
Iff the input to the transformer is ""
(the empty string), then the "rest" of any pending matches is
returned.
replacementString
- See Matcher.appendReplacement(StringBuffer, String)
Copyright © 2018 Arno Unkrig. All rights reserved.