stripStart and stripEnd methods changed to fulfill their javadoc.

Passing in strip("-+-+FOO---", "+-") will result in FOO.


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@136934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2002-07-19 04:04:45 +00:00
parent f01f3e8d3f
commit e488b7b892
2 changed files with 11 additions and 7 deletions

View File

@ -80,7 +80,7 @@
* @author <a href="mailto:ed@apache.org">Ed Korthof</a>
* @author <a href="mailto:rand_mcneely@yahoo.com>Rand McNeely</a>
* @author <a href="mailto:scolebourne@joda.org>Stephen Colebourne</a>
* @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++;
}
}

View File

@ -63,7 +63,7 @@
*
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:ridesmet@users.sourceforge.net">Ringo De Smet</a>
* @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 };