org.apache.commons.lang
Class CharSetUtils

java.lang.Object
  |
  +--org.apache.commons.lang.CharSetUtils

public class CharSetUtils
extends Object

Numerous routines to manipulate a character set.

Version:
$Id: CharSetUtils.java,v 1.6 2002/09/29 08:20:52 bayard Exp $
Author:
Henri Yandell, Stephen Colebourne

Constructor Summary
CharSetUtils()
          CharSetUtils instances should NOT be constructed in standard programming.
 
Method Summary
static int count(String str, String set)
          Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
static int count(String str, String[] set)
          Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string.
static String delete(String str, String set)
          Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.
static String delete(String str, String[] set)
          Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string.
static CharSet evaluateSet(String[] set)
          Creates a CharSetUtils object which allows a certain amount of set logic to be performed upon the following syntax: "aeio" which implies 'a','e',..
static String squeeze(String str, String set)
          Squeezes any repititions of a character that is mentioned in the supplied set.
static String squeeze(String str, String[] set)
          Squeezes any repititions of a character that is mentioned in the supplied set.
static String translate(String target, String repl, String with)
          Translate characters in a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharSetUtils

public CharSetUtils()
CharSetUtils instances should NOT be constructed in standard programming. Instead, the class should be used as CharSetUtils.evaluateSet(null);. This constructor is public to permit tools that require a JavaBean instance to operate.

Method Detail

evaluateSet

public static CharSet evaluateSet(String[] set)
Creates a CharSetUtils object which allows a certain amount of set logic to be performed upon the following syntax: "aeio" which implies 'a','e',.. "^e" implies not e. However it only negates, it's not a set in itself due to the size of that set in unicode. "ej-m" implies e,j->m. e,j,k,l,m.

Parameters:
set -
Returns:
CharSet
Throws:
NullPointerException - if any of set[i] is null or if set is null

squeeze

public static String squeeze(String str,
                             String set)
Squeezes any repititions of a character that is mentioned in the supplied set. An example is: squeeze("hello", "el") => "helo" See evaluateSet for set-syntax.

Parameters:
str - the string to work from
set - the character set to use for manipulation

squeeze

public static String squeeze(String str,
                             String[] set)
Squeezes any repititions of a character that is mentioned in the supplied set. An example is: squeeze("hello", {"el"}) => "helo" See evaluateSet for set-syntax.

Parameters:
str - the string to work from
set - the character set to use for manipulation
Throws:
NullPointerException - if str is null

count

public static int count(String str,
                        String set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string. An example would be: count("hello", {"c-f","o"}) returns 2.

Parameters:
str - String target to count characters in
set - String set of characters to count

count

public static int count(String str,
                        String[] set)
Takes an argument in set-syntax, see evaluateSet, and returns the number of characters present in the specified string. An example would be: count("hello", {"c-f","o"}) returns 2.

Parameters:
str - String target to count characters in
set - String[] set of characters to count

delete

public static String delete(String str,
                            String set)
Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string. An example would be: delete("hello", {"c-f","o"}) returns "hll"

Parameters:
str - String target to delete characters from
set - String set of characters to delete

delete

public static String delete(String str,
                            String[] set)
Takes an argument in set-syntax, see evaluateSet, and deletes any of characters present in the specified string. An example would be: delete("hello", {"c-f","o"}) returns "hll"

Parameters:
str - String target to delete characters from
set - String[] set of characters to delete
Throws:
NullPointerException - of str is null

translate

public static String translate(String target,
                               String repl,
                               String with)
Translate characters in a String. An example is: translate("hello", "ho", "jy") => jelly If the length of characters to search for is greater than the length of characters to replace, then the last character is used.

Parameters:
target - String to replace characters in
repl - String to find that will be replaced
with - String to put into the target String
Throws:
NullPointerException - if target, with or repl is null


Copyright (c) 2001-2002 - Apache Software Foundation