com.cleancode.format
Class REConverter

java.lang.Object
  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),
 };
 

Since:
CleanCode 0.9
Version:
$Revision: 9 $
Author:
Michael Sorens
See Also:
SimpleHtmlToText

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

VERSION

public static final String VERSION
Current version of this class.

Constructor Detail

REConverter

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

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

convert

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

Parameters:
content - a String containing the input
Returns:
a String containing the converted input


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