de.unkrig.commons.text.pattern
Class PatternUtil

java.lang.Object
  extended by de.unkrig.commons.text.pattern.PatternUtil

public final class PatternUtil
extends java.lang.Object

Pattern-related utility methods.


Nested Class Summary
static interface PatternUtil.Replacer
          Decides whether and how a match is to be replaced.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

replaceAll

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
Reads text from in, replaces all occurrences of pattern with replacement, 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.

Parameters:
context - Only for logging; e.g. the name of the file being transformed
Throws:
java.io.IOException

constantReplacer

public static PatternUtil.Replacer constantReplacer(java.lang.String context,
                                                    java.lang.String replacement)
Returns:
A PatternUtil.Replacer which constantly produces the given replacement

replaceAll

public 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
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.

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.

Parameters:
context - Only for logging; e.g. the name of the file being transformed
Returns:
The number of substitutions that were executed
Throws:
java.io.IOException