| java.lang.Object org.apache.commons.lang.CharSetUtils
CharSetUtils | public class CharSetUtils (Code) | | Operations on CharSet s.
This class handles null input gracefully.
An exception will not be thrown for a null input.
Each method documents its behaviour in more detail.
See Also: CharSet author: Stephen Colebourne author: Phil Steitz author: Gary Gregory since: 1.0 version: $Id: CharSetUtils.java 471626 2006-11-06 04:02:09Z bayard $ |
Constructor Summary | |
public | CharSetUtils() CharSetUtils instances should NOT be constructed in standard programming. |
Method Summary | |
public static int | count(String str, String set) | public static int | count(String str, String[] set) | public static String | delete(String str, String set) | public static String | delete(String str, String[] set) | public static CharSet | evaluateSet(String[] set) Creates a CharSet instance which allows a certain amount of
set logic to be performed.
The syntax is:
- "aeio" which implies 'a','e',..
- "^e" implies not e.
- "ej-m" implies e,j->m.
| public static String | keep(String str, String set) | public static String | keep(String str, String[] set) | public static String | squeeze(String str, String set) | public static String | squeeze(String str, String[] set) | public static String | translate(String str, String searchChars, String replaceChars) Translate characters in a String. |
CharSetUtils | public CharSetUtils()(Code) | | 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.
|
count | public static int count(String str, String set)(Code) | | Takes an argument in set-syntax, see evaluateSet,
and returns the number of characters present in the specified string.
CharSetUtils.count(null, *) = 0
CharSetUtils.count("", *) = 0
CharSetUtils.count(*, null) = 0
CharSetUtils.count(*, "") = 0
CharSetUtils.count("hello", "k-p") = 3
CharSetUtils.count("hello", "a-e") = 1
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to count characters in, may be null Parameters: set - String set of characters to count, may be null character count, zero if null string input |
count | public static int count(String str, String[] set)(Code) | | 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.
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to count characters in, may be null Parameters: set - String[] set of characters to count, may be null character count, zero if null string input |
delete | public static String delete(String str, String set)(Code) | | Takes an argument in set-syntax, see evaluateSet,
and deletes any of characters present in the specified string.
CharSetUtils.delete(null, *) = null
CharSetUtils.delete("", *) = ""
CharSetUtils.delete(*, null) = *
CharSetUtils.delete(*, "") = *
CharSetUtils.delete("hello", "hl") = "eo"
CharSetUtils.delete("hello", "le") = "ho"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to delete characters from, may be null Parameters: set - String set of characters to delete, may be null modified String, null if null string input |
delete | public static String delete(String str, String[] set)(Code) | | 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"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to delete characters from, may be null Parameters: set - String[] set of characters to delete, may be null modified String, null if null string input |
evaluateSet | public static CharSet evaluateSet(String[] set)(Code) | | Creates a CharSet instance which allows a certain amount of
set logic to be performed.
The syntax is:
- "aeio" which implies 'a','e',..
- "^e" implies not e.
- "ej-m" implies e,j->m. e,j,k,l,m.
CharSetUtils.evaluateSet(null) = null
CharSetUtils.evaluateSet([]) = CharSet matching nothing
CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
Parameters: set - the set, may be null a CharSet instance, null if null inputCharSet.getInstance(String) |
keep | public static String keep(String str, String set)(Code) | | Takes an argument in set-syntax, see evaluateSet,
and keeps any of characters present in the specified string.
CharSetUtils.keep(null, *) = null
CharSetUtils.keep("", *) = ""
CharSetUtils.keep(*, null) = ""
CharSetUtils.keep(*, "") = ""
CharSetUtils.keep("hello", "hl") = "hll"
CharSetUtils.keep("hello", "le") = "ell"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to keep characters from, may be null Parameters: set - String set of characters to keep, may be null modified String, null if null string input since: 2.0 |
keep | public static String keep(String str, String[] set)(Code) | | Takes an argument in set-syntax, see evaluateSet,
and keeps any of characters present in the specified string.
An example would be:
- keep("hello", {"c-f", "o"})
returns "eo"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - String to keep characters from, may be null Parameters: set - String[] set of characters to keep, may be null modified String, null if null string input since: 2.0 |
squeeze | public static String squeeze(String str, String set)(Code) | | Squeezes any repetitions of a character that is mentioned in the
supplied set.
CharSetUtils.squeeze(null, *) = null
CharSetUtils.squeeze("", *) = ""
CharSetUtils.squeeze(*, null) = *
CharSetUtils.squeeze(*, "") = *
CharSetUtils.squeeze("hello", "k-p") = "helo"
CharSetUtils.squeeze("hello", "a-e") = "hello"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - the string to squeeze, may be null Parameters: set - the character set to use for manipulation, may be null modified String, null if null string input |
squeeze | public static String squeeze(String str, String[] set)(Code) | | Squeezes any repetitions of a character that is mentioned in the
supplied set.
An example is:
- squeeze("hello", {"el"}) => "helo"
See Also: CharSetUtils.evaluateSet(java.lang.String[]) See Also: for set-syntax. Parameters: str - the string to squeeze, may be null Parameters: set - the character set to use for manipulation, may be null modified String, null if null string input |
translate | public static String translate(String str, String searchChars, String replaceChars)(Code) | | Translate characters in a String.
This is a multi character search and replace routine.
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.
CharSetUtils.translate(null, *, *) = null
CharSetUtils.translate("", *, *) = ""
Parameters: str - String to replace characters in, may be null Parameters: searchChars - a set of characters to search for, must not be null Parameters: replaceChars - a set of characters to replace, must not be null or empty ("") translated String, null if null string input throws: NullPointerException - if searchChars or replaceChars is null throws: ArrayIndexOutOfBoundsException - if replaceChars is empty ("")StringUtils.replaceChars(StringStringString) |
|
|