public final class PatternUtil
extends java.lang.Object
Pattern-related utility methods.| Modifier and Type | Class and Description |
|---|---|
static interface |
PatternUtil.Replacer
Decides whether and how a match is to be replaced.
|
| Modifier and Type | Method and Description |
|---|---|
static PatternUtil.Replacer |
constantReplacer(java.lang.String context,
java.lang.String replacement) |
static int |
replaceAll(java.lang.String context,
java.io.Reader in,
java.util.regex.Pattern pattern,
PatternUtil.Replacer replacer,
java.io.Writer out,
int initialBufferCapacity)
Reads text from in, finds all occurrences of pattern, replaces each with the result of
PatternUtil.Replacer.getReplacement(String, CharSequence), and writes the result to out. |
static void |
replaceAll(java.lang.String context,
java.io.Reader in,
java.util.regex.Pattern pattern,
java.lang.String replacement,
java.io.Writer out)
Reads text from in, replaces all occurrences of pattern with replacement, and
writes the result to out.
|
static int |
replaceSystemProperties(java.lang.String context,
java.io.Reader in,
java.io.Writer out)
Reads text from in, replaces all occurrences of
"
${system-property-name}" with the value of the system property, and writes
the result to out. |
static PatternUtil.Replacer |
systemPropertyReplacer() |
public static void replaceAll(java.lang.String context,
java.io.Reader in,
java.util.regex.Pattern pattern,
java.lang.String replacement,
java.io.Writer out)
throws java.io.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.
context - Only for logging; e.g. the name of the file being transformedjava.io.IOExceptionpublic static PatternUtil.Replacer constantReplacer(java.lang.String context, java.lang.String replacement)
PatternUtil.Replacer which constantly produces the given replacementpublic static PatternUtil.Replacer systemPropertyReplacer()
PatternUtil.Replacer which returns the value of the system property named by the matchpublic static int replaceSystemProperties(java.lang.String context,
java.io.Reader in,
java.io.Writer out)
throws java.io.IOException
${system-property-name}" with the value of the system property, and writes
the result to out.context - Only for logging; e.g. the name of the file being transformedjava.io.IOExceptionpublic static int replaceAll(java.lang.String context,
java.io.Reader in,
java.util.regex.Pattern pattern,
PatternUtil.Replacer replacer,
java.io.Writer out,
int initialBufferCapacity)
throws java.io.IOException
PatternUtil.Replacer.getReplacement(String, CharSequence), and writes the result to out.
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.
context - Only for logging; e.g. the name of the file being transformedjava.io.IOException