Class REConverter

  extended by com.cleancode.format.REConverter

public class REConverter
extends Object

Converts a text file using a series of regular expressions replacements. This class implements a completely generic text processing engine. You provide a set of regular-expression based rules, then invoke convert to run the engine. The simplest example is:

 static final REPiece[] PATTERNS = { ... };
 String outputText = (new REConverter(PATTERNS)).convert(inputText);
The devil is in the details, of course. That is, you need to define a set of regular expression rules in the PATTERNS variable. Here is the beginning of a set of rules to strip HTML markup from web text:
 static final REPiece[] PATTERNS = {
          new REPiece("italic",
            "<I>(.*?)</I>", "*$1*", Pattern.CASE_INSENSITIVE),
          new REPiece("rules",
            "<HR>", NL+"====================="+NL, Pattern.CASE_INSENSITIVE),
          new REPiece("non-breaking spaces",
            " ", " "),
          new REPiece("all other tags",
            "<[^>]*>", "", Pattern.DOTALL),

CleanCode 0.9
$Revision: 9 $
Michael Sorens
See Also:

Nested Class Summary
static class REConverter.REPiece
          A container class for holding regular expression objects to run against the input.
Field Summary
static String VERSION
          Current version of this class.
Constructor Summary
REConverter(REConverter.REPiece[] patterns)
          Construct a REConverter object.
Method Summary
 String convert(String content)
          Convert the specified input based on the specified rule set.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final String VERSION
Current version of this class.

Constructor Detail


public REConverter(REConverter.REPiece[] patterns)
Construct a REConverter object.

patterns - Array of regular expression specifications to process.
Method Detail


public String convert(String content)
Convert the specified input based on the specified rule set.

content - a String containing the input
a String containing the converted input

CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at Fast, secure and Free Open Source software downloads