diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index f2c7ad217..e73517e09 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -80,7 +80,7 @@ * @author Ed Korthof * @author Stephen Colebourne - * @version $Id: StringUtils.java,v 1.1 2002/07/19 03:35:54 bayard Exp $ + * @version $Id: StringUtils.java,v 1.2 2002/07/19 04:04:45 bayard Exp $ */ public class StringUtils { @@ -1001,7 +1001,7 @@ public static String[] stripAll(String[] strs, String delimiter) { } /** - * Strip any of a supplied string (first letter) from the end of a String.. + * Strip any of a supplied string from the end of a String.. * If the strip string is null, whitespace is stripped. * * @param str the string to remove characters from @@ -1019,8 +1019,7 @@ public static String stripEnd(String str, String strip) { end--; } } else { - char chr = strip.charAt(0); - while ((end != 0) && (str.charAt(end - 1) == chr)) { + while ((end != 0) && (strip.indexOf(str.charAt(end - 1)) != -1)) { end--; } } @@ -1028,7 +1027,7 @@ public static String stripEnd(String str, String strip) { } /** - * Strip any of a supplied string (first letter) from the start of a String. + * Strip any of a supplied string from the start of a String. * If the strip string is null, whitespace is stripped. * * @param str the string to remove characters from @@ -1050,7 +1049,7 @@ public static String stripStart(String str, String strip) { } } else { char chr = strip.charAt(0); - while ((start != sz) && (str.charAt(start) == chr)) { + while ((start != sz) && (strip.indexOf(str.charAt(start)) != -1)) { start++; } } diff --git a/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java b/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java index 587ea472e..abe89dc4e 100644 --- a/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java @@ -63,7 +63,7 @@ * * @author Stephen Colebourne * @author Ringo De Smet - * @version $Id: StringUtilsTrimEmptyTest.java,v 1.1 2002/07/19 03:35:55 bayard Exp $ + * @version $Id: StringUtilsTrimEmptyTest.java,v 1.2 2002/07/19 04:04:45 bayard Exp $ */ public class StringUtilsTrimEmptyTest extends TestCase { private static final String FOO = "foo"; @@ -134,6 +134,7 @@ public void testStrip() { String fooRightDots = FOO+"........."; assertEquals("", StringUtils.strip("")); + assertEquals("", StringUtils.strip(" ")); assertEquals(FOO, StringUtils.strip(foo2Space)); assertEquals(FOO, StringUtils.strip(foo2Dots, ".")); assertEquals(FOO, StringUtils.strip(fooRightSpace)); @@ -157,6 +158,10 @@ public void testStrip() { assertEquals(fooLeftSpace, StringUtils.stripEnd(fooLeftSpace, " ")); assertEquals(fooLeftDots, StringUtils.stripEnd(fooLeftDots, ".")); + assertEquals(FOO, StringUtils.strip(". . . . ."+FOO+". . ", " .")); + assertEquals("-."+FOO, StringUtils.strip(". . . . -."+FOO+". . ", " .")); + assertEquals(FOO, StringUtils.strip(".. .."+FOO+".. ", " .")); + // test stripAll method, merely an array version of the above strip String[] empty = new String[0]; String[] fooSpace = new String[] { foo2Space, fooLeftSpace, fooRightSpace };