Fix CharSetUtils to not throw NPE all the time

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137538 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-07-31 21:32:47 +00:00
parent 357851bdb1
commit 4926914ecb
3 changed files with 273 additions and 117 deletions

View File

@ -58,13 +58,12 @@ import java.util.LinkedList;
import java.util.List;
/**
* <p>A set of characters. You can iterate over the characters in the
* set.</p>
* <p>A set of characters.</p>
*
* @author <a href="bayard@generationjava.com">Henri Yandell</a>
* @author Stephen Colebourne
* @since 1.0
* @version $Id: CharSet.java,v 1.8 2003/03/23 17:59:09 scolebourne Exp $
* @version $Id: CharSet.java,v 1.9 2003/07/31 21:32:47 scolebourne Exp $
*/
public class CharSet {
@ -75,9 +74,18 @@ public class CharSet {
*
* <p>Use the factory method
* {@link CharSetUtils#evaluateSet(java.lang.String[])}.</p>
*/
protected CharSet(String set) {
add(set);
}
/**
* <p>Restricted constructor.</p>
*
* @throws NullPointerException if any of set[i] is <code>null</code>
* or if set is <code>null</code>
* <p>Use the factory method
* {@link CharSetUtils#evaluateSet(java.lang.String[])}.</p>
*
* @throws NullPointerException if set is <code>null</code>
*/
protected CharSet(String[] set) {
int sz = set.length;
@ -116,31 +124,33 @@ public class CharSet {
* <p>Add a set definition string to the <code>CharSet</code>.</p>
*
* @param str set definition string
* @throws NullPointerException if <code>str</code> is <code>null</code>
*/
protected void add(String str) {
if (str == null) {
return;
}
int sz = str.length();
CharRange range = null;
if("-".equals(str)) {
if ("-".equals(str)) {
range = new CharRange('-');
set.add(range);
return;
}
}
boolean end = false;
boolean negated = false;
for(int i=0; i<sz; i++) {
for (int i = 0; i < sz; i++) {
char ch = str.charAt(i);
if(ch == '-') {
if (ch == '-') {
end = true;
continue;
}
if(end) {
if (end) {
range.setEnd(ch);
continue;
}
if(ch == '^') {
if (ch == '^') {
negated = true;
continue;
}

View File

@ -56,14 +56,14 @@ package org.apache.commons.lang;
/**
* <p>Numerous routines to manipulate a <code>CharSet</code>.</p>
*
* <p>This class tries to handle <code>null</code> input gracefully.
* An exception will generally not be thrown for a <code>null</code> input.
* <p>This class handles <code>null</code> input gracefully.
* An exception will not be thrown for a <code>null</code> input.
* Each method documents its behaviour in more detail.</p>
*
* @author <a href="bayard@generationjava.com">Henri Yandell</a>
* @author Stephen Colebourne
* @since 1.0
* @version $Id: CharSetUtils.java,v 1.17 2003/07/31 20:38:26 scolebourne Exp $
* @version $Id: CharSetUtils.java,v 1.18 2003/07/31 21:32:47 scolebourne Exp $
*/
public class CharSetUtils {
@ -77,6 +77,7 @@ public class CharSetUtils {
public CharSetUtils() {
}
//-----------------------------------------------------------------------
/**
* <p>Creates a <code>CharSetUtils</code> object which allows a certain amount of
* set logic to be performed.</p>
@ -87,33 +88,72 @@ public class CharSetUtils {
* a set in itself due to the size of that set in unicode.</li>
* <li>&quot;ej-m&quot; implies e,j->m. e,j,k,l,m.</li>
* </ul>
*
* <pre>
* CharSetUtils.evaluateSet(null) = null
* CharSetUtils.evaluateSet("") = CharSet matching nothing
* CharSetUtils.evaluateSet("a-e") = CharSet matching a,b,c,d,e
* </pre>
*
* @param set the set, must not be null
* @return a CharSet instance
* @throws NullPointerException if any of set[i] is null or if set is null
* @param set the set, may be null
* @return a CharSet instance, <code>null</code> if null input
*/
public static CharSet evaluateSet(String set) {
if (set == null) {
return null;
}
return new CharSet(new String[] {set});
}
/**
* <p>Creates a <code>CharSetUtils</code> object which allows a certain amount of
* set logic to be performed.</p>
* <p>The syntax is:</p>
* <ul>
* <li>&quot;aeio&quot; which implies 'a','e',..</li>
* <li>&quot;^e&quot; implies not e. However it only negates, it's not
* a set in itself due to the size of that set in unicode.</li>
* <li>&quot;ej-m&quot; implies e,j->m. e,j,k,l,m.</li>
* </ul>
*
* <pre>
* CharSetUtils.evaluateSet(null) = null
* CharSetUtils.evaluateSet([]) = CharSet matching nothing
* CharSetUtils.evaluateSet(["a-e"]) = CharSet matching a,b,c,d,e
* </pre>
*
* @param set the set, may be null
* @return a CharSet instance, <code>null</code> if null input
*/
public static CharSet evaluateSet(String[] set) {
if (set == null) {
return null;
}
return new CharSet(set);
}
//-----------------------------------------------------------------------
/**
* <p>Squeezes any repititions of a character that is mentioned in the
* supplied set.</p>
*
* <p>An example is:</p>
* <ul>
* <li>squeeze(&quot;hello&quot;, &quot;el&quot;) => &quot;helo&quot;</li>
* </ul>
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* <pre>
* CharSetUtils.squeeze(null, *) = null
* CharSetUtils.squeeze("", *) = ""
* CharSetUtils.squeeze(*, null) = *
* CharSetUtils.squeeze(*, "") = *
* CharSetUtils.squeeze("hello", "k-p") = "helo"
* CharSetUtils.squeeze("hello", "a-e") = "hello"
* </pre>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str the string to squeeze, may be null
* @param set the character set to use for manipulation, must not be null
* @param set the character set to use for manipulation, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String squeeze(String str, String set) {
if (str == null) {
return null;
if (str == null || str.length() == 0 || set == null || set.length() == 0) {
return str;
}
String[] strs = new String[1];
strs[0] = set;
@ -128,17 +168,15 @@ public class CharSetUtils {
* <ul>
* <li>squeeze(&quot;hello&quot;, {&quot;el&quot;}) => &quot;helo&quot;</li>
* </ul>
* @see #evaluateSet(java.lang.String[]) for set-syntax.
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str the string to squeeze, may be null
* @param set the character set to use for manipulation, must not be null
* @param set the character set to use for manipulation, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
* or any element is <code>null</code>
*/
public static String squeeze(String str, String[] set) {
if (str == null) {
return null;
if (str == null || str.length() == 0 || set == null || set.length == 0) {
return str;
}
CharSet chars = evaluateSet(set);
StringBuffer buffer = new StringBuffer(str.length());
@ -159,22 +197,27 @@ public class CharSetUtils {
return buffer.toString();
}
//-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and returns the number of characters present in the specified string.</p>
*
* <p>An example would be:</p>
* <ul>
* <li>count(&quot;hello&quot;, {&quot;c-f&quot;, &quot;o&quot;}) returns 2.</li>
* </ul>
* <pre>
* 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
* </pre>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to count characters in, may be null
* @param set String set of characters to count, must not be null
* @param set String set of characters to count, may be null
* @return character count, zero if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static int count(String str, String set) {
if (str == null) {
if (str == null || str.length() == 0 || set == null || set.length() == 0) {
return 0;
}
String[] strs = new String[1];
@ -191,14 +234,13 @@ public class CharSetUtils {
* <li>count(&quot;hello&quot;, {&quot;c-f&quot;, &quot;o&quot;}) returns 2.</li>
* </ul>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to count characters in, may be null
* @param set String[] set of characters to count, must not be null
* @param set String[] set of characters to count, may be null
* @return character count, zero if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
* or any element is <code>null</code>
*/
public static int count(String str, String[] set) {
if (str == null) {
if (str == null || str.length() == 0 || set == null || set.length == 0) {
return 0;
}
CharSet chars = evaluateSet(set);
@ -213,24 +255,32 @@ public class CharSetUtils {
return count;
}
//-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and keeps any of characters present in the specified string.</p>
*
* <p>An example would be:</p>
* <ul>
* <li>keep(&quot;hello&quot;, {&quot;c-fo&quot;}) returns &quot;hll&quot;</li>
* </ul>
* <pre>
* CharSetUtils.keep(null, *) = null
* CharSetUtils.keep("", *) = ""
* CharSetUtils.keep(*, null) = ""
* CharSetUtils.keep(*, "") = ""
* CharSetUtils.keep("hello", "hl") = "hll"
* CharSetUtils.keep("hello", "le") = "ell"
* </pre>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to keep characters from, may be null
* @param set String set of characters to keep, must not be null
* @param set String set of characters to keep, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String keep(String str, String set) {
if (str == null) {
return null;
}
if (str.length() == 0 || set == null || set.length() == 0) {
return "";
}
String[] strs = new String[1];
strs[0] = set;
return keep(str, strs);
@ -246,36 +296,43 @@ public class CharSetUtils {
* returns &quot;hll&quot;</li>
* </ul>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to keep characters from, may be null
* @param set String[] set of characters to keep, must not be null
* @param set String[] set of characters to keep, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
* or any element is <code>null</code>
*/
public static String keep(String str, String[] set) {
if (str == null) {
return null;
}
if (str.length() == 0 || set == null || set.length == 0) {
return "";
}
return modify(str, set, true);
}
//-----------------------------------------------------------------------
/**
* <p>Takes an argument in set-syntax, see evaluateSet,
* and deletes any of characters present in the specified string.</p>
*
* <p>An example would be:</p>
* <ul>
* <li>delete(&quot;hello&quot;, {&quot;c-fo&quot;}) returns &quot;hll&quot;</li>
* </ul>
* <pre>
* CharSetUtils.delete(null, *) = null
* CharSetUtils.delete("", *) = ""
* CharSetUtils.delete(*, null) = *
* CharSetUtils.delete(*, "") = *
* CharSetUtils.delete("hello", "hl") = "hll"
* CharSetUtils.delete("hello", "le") = "ell"
* </pre>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to delete characters from, may be null
* @param set String set of characters to delete, must not be null
* @param set String set of characters to delete, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
*/
public static String delete(String str, String set) {
if (str == null) {
return null;
if (str == null || str.length() == 0 || set == null || set.length() == 0) {
return str;
}
String[] strs = new String[1];
strs[0] = set;
@ -292,19 +349,19 @@ public class CharSetUtils {
* &quot;hll&quot;</li>
* </ul>
*
* @see #evaluateSet(java.lang.String[]) for set-syntax.
* @param str String to delete characters from, may be null
* @param set String[] set of characters to delete, must not be null
* @param set String[] set of characters to delete, may be null
* @return modified String, <code>null</code> if null string input
* @throws NullPointerException if <code>set</code> is <code>null</code>
* or any element is <code>null</code>
*/
public static String delete(String str, String[] set) {
if (str == null) {
return null;
if (str == null || str.length() == 0 || set == null || set.length == 0) {
return str;
}
return modify(str, set, false);
}
//-----------------------------------------------------------------------
// Implementation of delete and keep
private static String modify(String str, String[] set, boolean expect) {
CharSet chars = evaluateSet(set);
@ -319,6 +376,7 @@ public class CharSetUtils {
return buffer.toString();
}
//-----------------------------------------------------------------------
/**
* <p>Translate characters in a String.
* This is a multi character search and replace routine.</p>

View File

@ -67,7 +67,7 @@ import junit.textui.TestRunner;
* @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @author Stephen Colebourne
* @version $Id: CharSetUtilsTest.java,v 1.10 2003/07/30 22:21:39 scolebourne Exp $
* @version $Id: CharSetUtilsTest.java,v 1.11 2003/07/31 21:32:47 scolebourne Exp $
*/
public class CharSetUtilsTest extends TestCase {
@ -104,72 +104,167 @@ public class CharSetUtilsTest extends TestCase {
}
//-----------------------------------------------------------------------
public void testSqueeze() {
assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
public void testEvaluateSet_String() {
assertEquals(null, CharSetUtils.evaluateSet((String) null));
assertEquals("[]", CharSetUtils.evaluateSet("").toString());
assertEquals("[a-e]", CharSetUtils.evaluateSet("a-e").toString());
}
public void testEvaluateSet_Stringarray() {
assertEquals(null, CharSetUtils.evaluateSet((String[]) null));
assertEquals("[]", CharSetUtils.evaluateSet(new String[0]).toString());
assertEquals("[]", CharSetUtils.evaluateSet(new String[] {null}).toString());
assertEquals("[a-e]", CharSetUtils.evaluateSet(new String[] {"a-e"}).toString());
}
//-----------------------------------------------------------------------
public void testSqueeze_StringString() {
assertEquals(null, CharSetUtils.squeeze(null, (String) null));
assertEquals(null, CharSetUtils.squeeze(null, new String[] { "el" }));
assertEquals("helo", CharSetUtils.squeeze("hello", new String[] { "el" }));
assertEquals(null, CharSetUtils.squeeze(null, ""));
assertEquals("", CharSetUtils.squeeze("", (String) null));
assertEquals("", CharSetUtils.squeeze("", ""));
assertEquals("", CharSetUtils.squeeze("", "a-e"));
assertEquals("hello", CharSetUtils.squeeze("hello", (String) null));
assertEquals("hello", CharSetUtils.squeeze("hello", ""));
assertEquals("", CharSetUtils.squeeze("", new String[] { "el" }));
assertEquals("hello", CharSetUtils.squeeze("hello", "a-e"));
assertEquals("helo", CharSetUtils.squeeze("hello", "l-p"));
}
public void testSqueeze_StringStringarray() {
assertEquals(null, CharSetUtils.squeeze(null, (String[]) null));
assertEquals(null, CharSetUtils.squeeze(null, new String[0]));
assertEquals(null, CharSetUtils.squeeze(null, new String[] {null}));
assertEquals(null, CharSetUtils.squeeze(null, new String[] {"el"}));
assertEquals("", CharSetUtils.squeeze("", (String[]) null));
assertEquals("", CharSetUtils.squeeze("", new String[0]));
assertEquals("", CharSetUtils.squeeze("", new String[] {null}));
assertEquals("", CharSetUtils.squeeze("", new String[] {"a-e"}));
assertEquals("hello", CharSetUtils.squeeze("hello", (String[]) null));
assertEquals("hello", CharSetUtils.squeeze("hello", new String[0]));
assertEquals("hello", CharSetUtils.squeeze("hello", new String[] {null}));
assertEquals("hello", CharSetUtils.squeeze("hello", new String[] {"a-e"}));
assertEquals("helo", CharSetUtils.squeeze("hello", new String[] { "el" }));
assertEquals("hello", CharSetUtils.squeeze("hello", new String[] { "e" }));
assertEquals("fofof", CharSetUtils.squeeze("fooffooff", new String[] { "of" }));
assertEquals("fof", CharSetUtils.squeeze("fooooff", new String[] { "fo" }));
try {
CharSetUtils.squeeze("hello", (String[]) null);
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
try {
CharSetUtils.squeeze("hello", new String[] { "", null });
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
}
public void testCount() {
assertEquals(0, CharSetUtils.count(null, (String[]) null));
//-----------------------------------------------------------------------
public void testCount_StringString() {
assertEquals(0, CharSetUtils.count(null, (String) null));
assertEquals(0, CharSetUtils.count(null, new String[] { "el" }));
assertEquals(0, CharSetUtils.count(null, ""));
assertEquals(0, CharSetUtils.count("", (String) null));
assertEquals(0, CharSetUtils.count("", ""));
assertEquals(0, CharSetUtils.count("", "a-e"));
assertEquals(0, CharSetUtils.count("hello", (String) null));
assertEquals(0, CharSetUtils.count("hello", ""));
assertEquals(1, CharSetUtils.count("hello", "a-e"));
assertEquals(3, CharSetUtils.count("hello", "l-p"));
}
public void testCount_StringStringarray() {
assertEquals(0, CharSetUtils.count(null, (String[]) null));
assertEquals(0, CharSetUtils.count(null, new String[0]));
assertEquals(0, CharSetUtils.count(null, new String[] {null}));
assertEquals(0, CharSetUtils.count(null, new String[] {"a-e"}));
assertEquals(0, CharSetUtils.count("", (String[]) null));
assertEquals(0, CharSetUtils.count("", new String[0]));
assertEquals(0, CharSetUtils.count("", new String[] {null}));
assertEquals(0, CharSetUtils.count("", new String[] {"a-e"}));
assertEquals(0, CharSetUtils.count("hello", (String[]) null));
assertEquals(0, CharSetUtils.count("hello", new String[0]));
assertEquals(0, CharSetUtils.count("hello", new String[] {null}));
assertEquals(1, CharSetUtils.count("hello", new String[] {"a-e"}));
assertEquals(3, CharSetUtils.count("hello", new String[] { "el" }));
assertEquals(0, CharSetUtils.count("", new String[] { "el" }));
assertEquals(0, CharSetUtils.count("hello", new String[] { "x" }));
assertEquals(2, CharSetUtils.count("hello", new String[] { "e-i" }));
assertEquals(5, CharSetUtils.count("hello", new String[] { "a-z" }));
assertEquals(0, CharSetUtils.count("hello", new String[] { "" }));
assertEquals(0, CharSetUtils.count("hello", ""));
try {
CharSetUtils.count("hello", (String[]) null);
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
try {
CharSetUtils.count("hello", new String[] { "", null });
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
}
public void testKeep() {
assertEquals(null, CharSetUtils.keep(null, (String[]) null));
//-----------------------------------------------------------------------
public void testKeep_StringString() {
assertEquals(null, CharSetUtils.keep(null, (String) null));
assertEquals(null, CharSetUtils.keep(null, new String[] { "el" }));
assertEquals(null, CharSetUtils.keep(null, ""));
assertEquals("", CharSetUtils.keep("", (String) null));
assertEquals("", CharSetUtils.keep("", ""));
assertEquals("", CharSetUtils.keep("", "a-e"));
assertEquals("", CharSetUtils.keep("hello", (String) null));
assertEquals("", CharSetUtils.keep("hello", ""));
assertEquals("", CharSetUtils.keep("hello", "xyz"));
assertEquals("hello", CharSetUtils.keep("hello", "a-z"));
assertEquals("hello", CharSetUtils.keep("hello", "oleh"));
assertEquals("ell", CharSetUtils.keep("hello", "el"));
}
public void testKeep_StringStringarray() {
assertEquals(null, CharSetUtils.keep(null, (String[]) null));
assertEquals(null, CharSetUtils.keep(null, new String[0]));
assertEquals(null, CharSetUtils.keep(null, new String[] {null}));
assertEquals(null, CharSetUtils.keep(null, new String[] {"a-e"}));
assertEquals("", CharSetUtils.keep("", (String[]) null));
assertEquals("", CharSetUtils.keep("", new String[0]));
assertEquals("", CharSetUtils.keep("", new String[] {null}));
assertEquals("", CharSetUtils.keep("", new String[] {"a-e"}));
assertEquals("", CharSetUtils.keep("hello", (String[]) null));
assertEquals("", CharSetUtils.keep("hello", new String[0]));
assertEquals("", CharSetUtils.keep("hello", new String[] {null}));
assertEquals("e", CharSetUtils.keep("hello", new String[] {"a-e"}));
assertEquals("e", CharSetUtils.keep("hello", new String[] { "a-e" }));
assertEquals("ell", CharSetUtils.keep("hello", new String[] { "el" }));
assertEquals("hello", CharSetUtils.keep("hello", new String[] { "elho" }));
assertEquals("", CharSetUtils.keep("hello", new String[] { "" }));
assertEquals("", CharSetUtils.keep("hello", ""));
assertEquals("hello", CharSetUtils.keep("hello", new String[] { "a-z" }));
assertEquals("----", CharSetUtils.keep("----", new String[] { "-" }));
assertEquals("ll", CharSetUtils.keep("hello", new String[] { "l" }));
try {
CharSetUtils.keep("hello", (String[]) null);
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
try {
CharSetUtils.keep("hello", new String[] { "", null});
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
}
public void testDelete() {
//-----------------------------------------------------------------------
public void testDelete_StringString() {
assertEquals(null, CharSetUtils.delete(null, (String) null));
assertEquals(null, CharSetUtils.delete(null, ""));
assertEquals("", CharSetUtils.delete("", (String) null));
assertEquals("", CharSetUtils.delete("", ""));
assertEquals("", CharSetUtils.delete("", "a-e"));
assertEquals("hello", CharSetUtils.delete("hello", (String) null));
assertEquals("hello", CharSetUtils.delete("hello", ""));
assertEquals("hllo", CharSetUtils.delete("hello", "a-e"));
assertEquals("he", CharSetUtils.delete("hello", "l-p"));
assertEquals("hello", CharSetUtils.delete("hello", "z"));
}
public void testDelete_StringStringarray() {
assertEquals(null, CharSetUtils.delete(null, (String[]) null));
assertEquals(null, CharSetUtils.delete(null,(String) null));
assertEquals(null, CharSetUtils.delete(null, new String[] { "el" }));
assertEquals(null, CharSetUtils.delete(null, new String[0]));
assertEquals(null, CharSetUtils.delete(null, new String[] {null}));
assertEquals(null, CharSetUtils.delete(null, new String[] {"el"}));
assertEquals("", CharSetUtils.delete("", (String[]) null));
assertEquals("", CharSetUtils.delete("", new String[0]));
assertEquals("", CharSetUtils.delete("", new String[] {null}));
assertEquals("", CharSetUtils.delete("", new String[] {"a-e"}));
assertEquals("hello", CharSetUtils.delete("hello", (String[]) null));
assertEquals("hello", CharSetUtils.delete("hello", new String[0]));
assertEquals("hello", CharSetUtils.delete("hello", new String[] {null}));
assertEquals("hello", CharSetUtils.delete("hello", new String[] {"xyz"}));
assertEquals("ho", CharSetUtils.delete("hello", new String[] { "el" }));
assertEquals("", CharSetUtils.delete("hello", new String[] { "elho" }));
assertEquals("hello", CharSetUtils.delete("hello", new String[] { "" }));
@ -177,16 +272,9 @@ public class CharSetUtilsTest extends TestCase {
assertEquals("", CharSetUtils.delete("hello", new String[] { "a-z" }));
assertEquals("", CharSetUtils.delete("----", new String[] { "-" }));
assertEquals("heo", CharSetUtils.delete("hello", new String[] { "l" }));
try {
CharSetUtils.delete("hello", (String[]) null);
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
try {
CharSetUtils.delete("hello", new String[] { "-", null });
fail("Expecting NullPointerException");
} catch (NullPointerException ex) {}
}
//-----------------------------------------------------------------------
public void testTranslate() {
assertEquals(null, CharSetUtils.translate(null, null, null));
assertEquals("", CharSetUtils.translate("","a", "b"));