org.openbp.common.string
Class StringReplacer

java.lang.Object
  extended by org.openbp.common.string.StringReplacer

public class StringReplacer
extends java.lang.Object

Utility class that replaces patterns in a string with replacement strings. Supports case-insensitive replacements. Also optionally trims spaces inside the string.

Author:
Heiko Erhardt

Constructor Summary
StringReplacer()
          Constructor.
 
Method Summary
 void addReplacement(java.lang.String pattern, java.lang.String replacement)
          Adds a pattern to the replacer.
 java.lang.String process(java.lang.String s)
          Performs the processing.
 void setIgnoreCase(boolean ignoreCase)
          Sets the ignore case option.
 void setTrim(boolean trim)
          Sets the trim mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringReplacer

public StringReplacer()
Constructor.

Method Detail

addReplacement

public void addReplacement(java.lang.String pattern,
                           java.lang.String replacement)
Adds a pattern to the replacer.

Parameters:
pattern - The pattern
replacement - The substitute that will replace the pattern in the string or null to remove the pattern from the string

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Sets the ignore case option.

Parameters:
ignoreCase - true The character case will be ignored when comparing strings.
false The pattern matcher will distinguish between lower and upper case.

setTrim

public void setTrim(boolean trim)
Sets the trim mode.

Parameters:
trim - true Removes overflous spaces and newlines, i. e. skips succeeding newslines and spaces
false Leaves spaces and newlines as they are

process

public java.lang.String process(java.lang.String s)
Performs the processing.

Parameters:
s - String to process
Returns:
The result of the processing


Copyright © 2011. All Rights Reserved.