diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index a6738ec26..179889165 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -74,7 +74,7 @@ import java.util.List; * - index of any of a set of Strings *
  • ContainsOnly/ContainsNone * - does String contain only/none of these characters - *
  • SubString/Left/Right/Mid + *
  • SubString/Left/Right/Mid/SubStringBefore/SubStringAfter * - null-safe substring extraction *
  • Split * - splits a String into an array of subtrings based on a separator @@ -82,8 +82,8 @@ import java.util.List; * - joins an array of Strings into one with optional separator *
  • Replace/Delete/Overlay * - Searches a String and replaces one String with another - *
  • Chomp/Chop/Slice - * - searches a String and returns the substring before/after the separator + *
  • Chomp/Chop + * - removes the last part of a String *
  • LeftPad/RightPad/Center/Repeat * - pads a String *
  • UpperCase/LowerCase/SwapCase/Capitalise/Uncapitalise @@ -146,7 +146,7 @@ import java.util.List; * @author Gary Gregory * @author Phil Steitz * @since 1.0 - * @version $Id: StringUtils.java,v 1.78 2003/07/25 00:50:00 scolebourne Exp $ + * @version $Id: StringUtils.java,v 1.79 2003/07/25 22:22:30 scolebourne Exp $ */ public class StringUtils { // Performance testing notes (JDK 1.4, Jul03, scolebourne) @@ -1547,6 +1547,161 @@ public class StringUtils { } } + // SubStringAfter/SubStringBefore + //----------------------------------------------------------------------- + + /** + *

    Gets the substring before the first occurance of a separator. + * The separator is not returned.

    + * + *

    A null string input will return null. + * An empty ("") string input will return the empty string. + * A null separator will return the input string.

    + * + *
    +     * StringUtils.substringBefore(null, *)      = null
    +     * StringUtils.substringBefore("", *)        = ""
    +     * StringUtils.substringBefore("abc", "a")   = ""
    +     * StringUtils.substringBefore("abcba", "b") = "a"
    +     * StringUtils.substringBefore("abc", "c")   = "ab"
    +     * StringUtils.substringBefore("abc", "d")   = "abc"
    +     * StringUtils.substringBefore("abc", "")    = ""
    +     * StringUtils.substringBefore("abc", null)  = "abc"
    +     * 
    + * + * @param str the String to get a substring from, may be null + * @param separator the String to search for, may be null + * @return the substring before the first occurance of the separator, + * null if null String input + */ + public static String substringBefore(String str, String separator) { + if (str == null || separator == null || str.length() == 0) { + return str; + } + if (separator.length() == 0) { + return ""; + } + int pos = str.indexOf(separator); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + /** + *

    Gets the substring after the first occurance of a separator. + * The separator is not returned.

    + * + *

    A null string input will return null. + * An empty ("") string input will return the empty string. + * A null separator will return the empty string if the + * input string is not null.

    + * + *
    +     * StringUtils.substringAfter(null, *)      = null
    +     * StringUtils.substringAfter("", *)        = ""
    +     * StringUtils.substringAfter(*, null)      = ""
    +     * StringUtils.substringAfter("abc", "a")   = "bc"
    +     * StringUtils.substringAfter("abcba", "b") = "cba"
    +     * StringUtils.substringAfter("abc", "c")   = ""
    +     * StringUtils.substringAfter("abc", "d")   = ""
    +     * StringUtils.substringAfter("abc", "")    = "abc"
    +     * 
    + * + * @param str the String to get a substring from, may be null + * @param separator the String to search for, may be null + * @return the substring after the first occurance of the separator, + * null if null String input + */ + public static String substringAfter(String str, String separator) { + if (str == null || str.length() == 0) { + return str; + } + if (separator == null) { + return ""; + } + int pos = str.indexOf(separator); + if (pos == -1) { + return ""; + } + return str.substring(pos + separator.length()); + } + + /** + *

    Gets the substring before the last occurance of a separator. + * The separator is not returned.

    + * + *

    A null string input will return null. + * An empty ("") string input will return the empty string. + * An empty or null separator will return the input string.

    + * + *
    +     * StringUtils.substringBeforeLast(null, *)      = null
    +     * StringUtils.substringBeforeLast("", *)        = ""
    +     * StringUtils.substringBeforeLast("abcba", "b") = "abc"
    +     * StringUtils.substringBeforeLast("abc", "c")   = "ab"
    +     * StringUtils.substringBeforeLast("a", "a")     = ""
    +     * StringUtils.substringBeforeLast("a", "z")     = "a"
    +     * StringUtils.substringBeforeLast("a", null)    = "a"
    +     * StringUtils.substringBeforeLast("a", "")      = "a"
    +     * 
    + * + * @param str the String to get a substring from, may be null + * @param separator the String to search for, may be null + * @return the substring before the last occurance of the separator, + * null if null String input + */ + public static String substringBeforeLast(String str, String separator) { + if (str == null || separator == null || str.length() == 0 || separator.length() == 0) { + return str; + } + int pos = str.lastIndexOf(separator); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + /** + *

    Gets the substring after the last occurance of a separator. + * The separator is not returned.

    + * + *

    A null string input will return null. + * An empty ("") string input will return the empty string. + * An empty or null separator will return the empty string if + * the input string is not null.

    + * + *
    +     * StringUtils.substringAfterLast(null, *)      = null
    +     * StringUtils.substringAfterLast("", *)        = ""
    +     * StringUtils.substringAfterLast(*, "")        = ""
    +     * StringUtils.substringAfterLast(*, null)      = ""
    +     * StringUtils.substringAfterLast("abc", "a")   = "bc"
    +     * StringUtils.substringAfterLast("abcba", "b") = "a"
    +     * StringUtils.substringAfterLast("abc", "c")   = ""
    +     * StringUtils.substringAfterLast("a", "a")     = ""
    +     * StringUtils.substringAfterLast("a", "z")     = ""
    +     * 
    + * + * @param str the String to get a substring from, may be null + * @param separator the String to search for, may be null + * @return the substring after the last occurance of the separator, + * null if null String input + */ + public static String substringAfterLast(String str, String separator) { + if (str == null || str.length() == 0) { + return str; + } + if (separator == null || separator.length() == 0) { + return ""; + } + int pos = str.lastIndexOf(separator); + if (pos == -1 || pos == (str.length() - separator.length())) { + return ""; + } + return str.substring(pos + separator.length()); + } + // Splitting //----------------------------------------------------------------------- @@ -2145,8 +2300,7 @@ public class StringUtils { * "\r", or "\r\n".

    * *

    NOTE: This method changed in 2.0. - * It now more closely matches Perl chomp. - * For the previous behavior, use {@link #slice(String)}.

    + * It now more closely matches Perl chomp.

    * *
          * StringUtils.chomp(null)          = null
    @@ -2200,7 +2354,7 @@ public class StringUtils {
          *
          * 

    NOTE: This method changed in version 2.0. * It now more closely matches Perl chomp. - * For the previous behavior, use {@link #slice(String,String)}. + * For the previous behavior, use {@link #substringBeforeLast(String, String)}. * This method uses {@link String#endsWith(String)}.

    * *
    @@ -2268,14 +2422,14 @@ public class StringUtils {
     
         /** 
          * 

    Remove everything and return the last value of a supplied String, and - * everything after it from a String. - * [That makes no sense. Just use sliceRemainder() :-)]

    + * everything after it from a String.

    * * @param str the String to chomp from, must not be null * @param sep the String to chomp, must not be null * @return String chomped * @throws NullPointerException if str or sep is null - * @deprecated Use {@link #sliceRemainder(String,String)} instead. + * @deprecated Use {@link #substringAfterLast(String, String)} instead + * (although this doesn't include the separator) * Method will be removed in Commons Lang 3.0. */ public static String getChomp(String str, String sep) { @@ -2297,7 +2451,7 @@ public class StringUtils { * @param sep the String to chomp, must not be null * @return String without chomped beginning * @throws NullPointerException if str or sep is null - * @deprecated Use {@link #sliceFirstRemainder(String,String)} instead. + * @deprecated Use {@link #substringAfter(String,String)} instead. * Method will be removed in Commons Lang 3.0. */ public static String prechomp(String str, String sep) { @@ -2317,7 +2471,8 @@ public class StringUtils { * @param sep the String to chomp, must not be null * @return String prechomped * @throws NullPointerException if str or sep is null - * @deprecated Use {@link #sliceFirst(String,String)} instead. + * @deprecated Use {@link #substringBefore(String,String)} instead + * (although this doesn't include the separator) * Method will be removed in Commons Lang 3.0. */ public static String getPrechomp(String str, String sep) { @@ -2401,195 +2556,6 @@ public class StringUtils { } - // Slicing - //----------------------------------------------------------------------- - - /** - *

    Removes the last newline, and everything after it from a String.

    - * - *

    A null string input will return null. - * An empty ("") string input will return the empty string.

    - * - *
    -     * StringUtils.slice(null)          = null
    -     * StringUtils.slice("")            = ""
    -     * StringUtils.slice("abc \n")      = "abc "
    -     * StringUtils.slice("abc\n")       = "abc"
    -     * StringUtils.slice("abc\r\n")     = "abc\r"
    -     * StringUtils.slice("abc")         = "abc"
    -     * StringUtils.slice("abc\nabc")    = "abc"
    -     * StringUtils.slice("abc\nabc\n")  = "abc\nabc"
    -     * StringUtils.slice("\n")          = ""
    -     * 
    - * - *

    (This method was formerly named chomp or chopNewline.)

    - * - * @param str the String to slice the newline from, may be null - * @return String without sliced newline, null if null String input - */ - public static String slice(String str) { - return slice(str, "\n"); - } - - /** - *

    Finds the last occurence of a separator String, - * returning everything before it. The separator is not returned.

    - * - *

    A null string input will return null. - * An empty ("") string input will return the empty string. - * An empty or null separator will return the input string.

    - * - *
    -     * StringUtils.slice(null, *)      = null
    -     * StringUtils.slice("", *)        = ""
    -     * StringUtils.slice("abcba", "b") = "abc"
    -     * StringUtils.slice("abc", "c")   = "ab"
    -     * StringUtils.slice("a", "a")     = ""
    -     * StringUtils.slice("a", "z")     = "a"
    -     * StringUtils.slice("a", null)    = "a"
    -     * StringUtils.slice("a", "")      = "a"
    -     * 
    - * - *

    (This method was formerly named chomp.)

    - * - * @param str the String to slice from, may be null - * @param separator the String to slice, may be null - * @return String without sliced ending, null if null String input - */ - public static String slice(String str, String separator) { - if (str == null || separator == null || str.length() == 0 || separator.length() == 0) { - return str; - } - int pos = str.lastIndexOf(separator); - if (pos == -1) { - return str; - } - return str.substring(0, pos); - } - - /** - *

    Finds the last occurence of a separator String, - * returning everything after it.

    - * - *

    A null string input will return null. - * An empty ("") string input will return the empty string. - * An empty or null separator will return the empty string if - * the input string is not null.

    - * - *
    -     * StringUtils.sliceRemainder(null, *)         = null
    -     * StringUtils.sliceRemainder("", *)           = ""
    -     * StringUtils.sliceRemainder(*, "")           = ""
    -     * StringUtils.sliceRemainder(*, null)         = ""
    -     * StringUtils.sliceRemainder("abc", "a")      = "bc"
    -     * StringUtils.sliceRemainder("abcba", "b")    = "a"
    -     * StringUtils.sliceRemainder("abc", "c")      = ""
    -     * StringUtils.sliceRemainder("a", "a")        = ""
    -     * StringUtils.sliceRemainder("a", "z")        = ""
    -     * 
    - * - *

    (This method was formerly named getchomp. Also, now it does not - * include the separator in the return value.)

    - * - * @param str the String to slice from, may be null - * @param separator the String to slice, may be null - * @return String sliced, null if null String input - */ - public static String sliceRemainder(String str, String separator) { - if (str == null || str.length() == 0) { - return str; - } - if (separator == null || separator.length() == 0) { - return ""; - } - int pos = str.lastIndexOf(separator); - if (pos == -1 || pos == (str.length() - separator.length())) { - return ""; - } - return str.substring(pos + separator.length()); - } - - /** - *

    Finds the first occurence of a separator String, - * returning everything before it. The separator is not returned.

    - * - *

    A null string input will return null. - * An empty ("") string input will return the empty string. - * A null separator will return the input string.

    - * - *
    -     * StringUtils.sliceFirst(null, *)         = null
    -     * StringUtils.sliceFirst("", *)           = ""
    -     * StringUtils.sliceFirst("abc", "a")      = ""
    -     * StringUtils.sliceFirst("abcba", "b")    = "a"
    -     * StringUtils.sliceFirst("abc", "c")      = "ab"
    -     * StringUtils.sliceFirst("abc", "d")      = "abc"
    -     * StringUtils.sliceFirst("abc", "")       = ""
    -     * StringUtils.sliceFirst("abc", null)     = "abc"
    -     * 
    - * - *

    (This method was formerly named getPrechomp. Also, it used to - * include the separator, but now it does not.)

    - * - * @param str the String to slice from, may be null - * @param separator the String to slice, may be null - * @return sliced String, null if null String input - */ - public static String sliceFirst(String str, String separator) { - if (str == null || separator == null || str.length() == 0) { - return str; - } - if (separator.length() == 0) { - return ""; - } - int pos = str.indexOf(separator); - if (pos == -1) { - return str; - } - return str.substring(0, pos); - } - - /** - *

    Finds the first occurence of a separator String, - * returning everything after it.

    - * - *

    A null string input will return null. - * An empty ("") string input will return the empty string. - * A null separator will return the empty string if the - * input string is not null.

    - * - *
    -     * StringUtils.sliceFirstRemainder(null, *)      = null
    -     * StringUtils.sliceFirstRemainder("", *)        = ""
    -     * StringUtils.sliceFirstRemainder(*, null)      = ""
    -     * StringUtils.sliceFirstRemainder("abc", "a")   = "bc"
    -     * StringUtils.sliceFirstRemainder("abcba", "b") = "cba"
    -     * StringUtils.sliceFirstRemainder("abc", "c")   = ""
    -     * StringUtils.sliceFirstRemainder("abc", "d")   = ""
    -     * StringUtils.sliceFirstRemainder("abc", "")    = "abc"
    -     * 
    - * - *

    (This method was formerly named prechomp. Also, previously - * it included the separator in the return value; now it does not.)

    - * - * @param str the String to slice from, may be null - * @param separator the String to slice, may be null - * @return String without sliced beginning, null if null String input - */ - public static String sliceFirstRemainder(String str, String separator) { - if (str == null || str.length() == 0) { - return str; - } - if (separator == null) { - return ""; - } - int pos = str.indexOf(separator); - if (pos == -1) { - return ""; - } - return str.substring(pos + separator.length()); - } - // Conversion //----------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/lang/StringUtilsSubstringTest.java b/src/test/org/apache/commons/lang/StringUtilsSubstringTest.java index bdca8bf1f..2b3f65054 100644 --- a/src/test/org/apache/commons/lang/StringUtilsSubstringTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsSubstringTest.java @@ -64,7 +64,7 @@ import junit.textui.TestRunner; * @author Stephen Colebourne * @author Ringo De Smet * @author Phil Steitz - * @version $Id: StringUtilsSubstringTest.java,v 1.8 2003/07/21 00:41:13 scolebourne Exp $ + * @version $Id: StringUtilsSubstringTest.java,v 1.9 2003/07/25 22:22:30 scolebourne Exp $ */ public class StringUtilsSubstringTest extends TestCase { private static final String FOO = "foo"; @@ -178,6 +178,89 @@ public class StringUtilsSubstringTest extends TestCase { } catch (IllegalArgumentException ex) {} } + //----------------------------------------------------------------------- + public void testSubstringBefore_StringString() { + assertEquals("foo", StringUtils.substringBefore("fooXXbarXXbaz", "XX")); + + assertEquals(null, StringUtils.substringBefore(null, null)); + assertEquals(null, StringUtils.substringBefore(null, "")); + assertEquals(null, StringUtils.substringBefore(null, "XX")); + assertEquals("", StringUtils.substringBefore("", null)); + assertEquals("", StringUtils.substringBefore("", "")); + assertEquals("", StringUtils.substringBefore("", "XX")); + + assertEquals("foo", StringUtils.substringBefore("foo", null)); + assertEquals("foo", StringUtils.substringBefore("foo", "b")); + assertEquals("f", StringUtils.substringBefore("foot", "o")); + assertEquals("", StringUtils.substringBefore("abc", "a")); + assertEquals("a", StringUtils.substringBefore("abcba", "b")); + assertEquals("ab", StringUtils.substringBefore("abc", "c")); + assertEquals("", StringUtils.substringBefore("abc", "")); + } + + public void testSubstringAfter_StringString() { + assertEquals("barXXbaz", StringUtils.substringAfter("fooXXbarXXbaz", "XX")); + + assertEquals(null, StringUtils.substringAfter(null, null)); + assertEquals(null, StringUtils.substringAfter(null, "")); + assertEquals(null, StringUtils.substringAfter(null, "XX")); + assertEquals("", StringUtils.substringAfter("", null)); + assertEquals("", StringUtils.substringAfter("", "")); + assertEquals("", StringUtils.substringAfter("", "XX")); + + assertEquals("", StringUtils.substringAfter("foo", null)); + assertEquals("ot", StringUtils.substringAfter("foot", "o")); + assertEquals("bc", StringUtils.substringAfter("abc", "a")); + assertEquals("cba", StringUtils.substringAfter("abcba", "b")); + assertEquals("", StringUtils.substringAfter("abc", "c")); + assertEquals("abc", StringUtils.substringAfter("abc", "")); + assertEquals("", StringUtils.substringAfter("abc", "d")); + } + + public void testSubstringBeforeLast_StringString() { + assertEquals("fooXXbar", StringUtils.substringBeforeLast("fooXXbarXXbaz", "XX")); + + assertEquals(null, StringUtils.substringBeforeLast(null, null)); + assertEquals(null, StringUtils.substringBeforeLast(null, "")); + assertEquals(null, StringUtils.substringBeforeLast(null, "XX")); + assertEquals("", StringUtils.substringBeforeLast("", null)); + assertEquals("", StringUtils.substringBeforeLast("", "")); + assertEquals("", StringUtils.substringBeforeLast("", "XX")); + + assertEquals("foo", StringUtils.substringBeforeLast("foo", null)); + assertEquals("foo", StringUtils.substringBeforeLast("foo", "b")); + assertEquals("fo", StringUtils.substringBeforeLast("foo", "o")); + assertEquals("abc\r\n", StringUtils.substringBeforeLast("abc\r\n", "d")); + assertEquals("abc", StringUtils.substringBeforeLast("abcdabc", "d")); + assertEquals("abcdabc", StringUtils.substringBeforeLast("abcdabcd", "d")); + assertEquals("a", StringUtils.substringBeforeLast("abc", "b")); + assertEquals("abc ", StringUtils.substringBeforeLast("abc \n", "\n")); + assertEquals("a", StringUtils.substringBeforeLast("a", null)); + assertEquals("a", StringUtils.substringBeforeLast("a", "")); + assertEquals("", StringUtils.substringBeforeLast("a", "a")); + } + + public void testSubstringAfterLast_StringString() { + assertEquals("baz", StringUtils.substringAfterLast("fooXXbarXXbaz", "XX")); + + assertEquals(null, StringUtils.substringAfterLast(null, null)); + assertEquals(null, StringUtils.substringAfterLast(null, "")); + assertEquals(null, StringUtils.substringAfterLast(null, "XX")); + assertEquals("", StringUtils.substringAfterLast("", null)); + assertEquals("", StringUtils.substringAfterLast("", "")); + assertEquals("", StringUtils.substringAfterLast("", "a")); + + assertEquals("", StringUtils.substringAfterLast("foo", null)); + assertEquals("", StringUtils.substringAfterLast("foo", "b")); + assertEquals("t", StringUtils.substringAfterLast("foot", "o")); + assertEquals("bc", StringUtils.substringAfterLast("abc", "a")); + assertEquals("a", StringUtils.substringAfterLast("abcba", "b")); + assertEquals("", StringUtils.substringAfterLast("abc", "c")); + assertEquals("", StringUtils.substringAfterLast("", "d")); + assertEquals("", StringUtils.substringAfterLast("abc", "")); + } + + //----------------------------------------------------------------------- public void testCountMatches_String() { assertEquals(0, StringUtils.countMatches(null, null)); assertEquals(0, StringUtils.countMatches("blah", null)); diff --git a/src/test/org/apache/commons/lang/StringUtilsTest.java b/src/test/org/apache/commons/lang/StringUtilsTest.java index 10fd0fecd..94d9d4a77 100644 --- a/src/test/org/apache/commons/lang/StringUtilsTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsTest.java @@ -72,7 +72,7 @@ import junit.textui.TestRunner; * @author Holger Krauth * @author Henning P. Schmiedehausen * @author Phil Steitz - * @version $Id: StringUtilsTest.java,v 1.38 2003/07/25 00:50:00 scolebourne Exp $ + * @version $Id: StringUtilsTest.java,v 1.39 2003/07/25 22:22:30 scolebourne Exp $ */ public class StringUtilsTest extends TestCase { @@ -573,109 +573,6 @@ public class StringUtilsTest extends TestCase { } } - public void testSliceFunctions() { - - String[][] sliceCases = { - {"foo\n", "foo"}, - {"foo\nbar", "foo"}, - {"foo\nbar\n", "foo\nbar"}, - {"foo\nbar\nbaz", "foo\nbar"}, - {null, null}, - {"", ""}, - {"\n", ""}, - {"abc \n", "abc "}, - {"abc\r\n", "abc\r"}, - {"foo", "foo"}, - }; - for (int i = 0; i < sliceCases.length; i++) { - String original = sliceCases[i][0]; - String expectedResult = sliceCases[i][1]; - assertEquals("slice(String) failed", - expectedResult, StringUtils.slice(original)); - } - } - - public void testSlice_StringString() { - assertEquals("fooXXbar", StringUtils.slice("fooXXbarXXbaz", "XX")); - - assertEquals(null, StringUtils.slice(null, null)); - assertEquals(null, StringUtils.slice(null, "")); - assertEquals(null, StringUtils.slice(null, "XX")); - assertEquals("", StringUtils.slice("", null)); - assertEquals("", StringUtils.slice("", "")); - assertEquals("", StringUtils.slice("", "XX")); - - assertEquals("foo", StringUtils.slice("foo", null)); - assertEquals("foo", StringUtils.slice("foo", "b")); - assertEquals("fo", StringUtils.slice("foo", "o")); - assertEquals("abc\r\n", StringUtils.slice("abc\r\n", "d")); - assertEquals("abc", StringUtils.slice("abcdabc", "d")); - assertEquals("abcdabc", StringUtils.slice("abcdabcd", "d")); - assertEquals("a", StringUtils.slice("abc", "b")); - assertEquals("abc ", StringUtils.slice("abc \n", "\n")); - assertEquals("a", StringUtils.slice("a", null)); - assertEquals("a", StringUtils.slice("a", "")); - assertEquals("", StringUtils.slice("a", "a")); - } - - public void testSliceRemainder_StringString() { - assertEquals("baz", StringUtils.sliceRemainder("fooXXbarXXbaz", "XX")); - - assertEquals(null, StringUtils.sliceRemainder(null, null)); - assertEquals(null, StringUtils.sliceRemainder(null, "")); - assertEquals(null, StringUtils.sliceRemainder(null, "XX")); - assertEquals("", StringUtils.sliceRemainder("", null)); - assertEquals("", StringUtils.sliceRemainder("", "")); - assertEquals("", StringUtils.sliceRemainder("", "a")); - - assertEquals("", StringUtils.sliceRemainder("foo", null)); - assertEquals("", StringUtils.sliceRemainder("foo", "b")); - assertEquals("t", StringUtils.sliceRemainder("foot", "o")); - assertEquals("bc", StringUtils.sliceRemainder("abc", "a")); - assertEquals("a", StringUtils.sliceRemainder("abcba", "b")); - assertEquals("", StringUtils.sliceRemainder("abc", "c")); - assertEquals("", StringUtils.sliceRemainder("", "d")); - assertEquals("", StringUtils.sliceRemainder("abc", "")); - } - - public void testSliceFirst_StringString() { - assertEquals("foo", StringUtils.sliceFirst("fooXXbarXXbaz", "XX")); - - assertEquals(null, StringUtils.sliceFirst(null, null)); - assertEquals(null, StringUtils.sliceFirst(null, "")); - assertEquals(null, StringUtils.sliceFirst(null, "XX")); - assertEquals("", StringUtils.sliceFirst("", null)); - assertEquals("", StringUtils.sliceFirst("", "")); - assertEquals("", StringUtils.sliceFirst("", "XX")); - - assertEquals("foo", StringUtils.sliceFirst("foo", null)); - assertEquals("foo", StringUtils.sliceFirst("foo", "b")); - assertEquals("f", StringUtils.sliceFirst("foot", "o")); - assertEquals("", StringUtils.sliceFirst("abc", "a")); - assertEquals("a", StringUtils.sliceFirst("abcba", "b")); - assertEquals("ab", StringUtils.sliceFirst("abc", "c")); - assertEquals("", StringUtils.sliceFirst("abc", "")); - } - - public void testSliceFirstRemainder_StringString() { - assertEquals("barXXbaz", StringUtils.sliceFirstRemainder("fooXXbarXXbaz", "XX")); - - assertEquals(null, StringUtils.sliceFirstRemainder(null, null)); - assertEquals(null, StringUtils.sliceFirstRemainder(null, "")); - assertEquals(null, StringUtils.sliceFirstRemainder(null, "XX")); - assertEquals("", StringUtils.sliceFirstRemainder("", null)); - assertEquals("", StringUtils.sliceFirstRemainder("", "")); - assertEquals("", StringUtils.sliceFirstRemainder("", "XX")); - - assertEquals("", StringUtils.sliceFirstRemainder("foo", null)); - assertEquals("ot", StringUtils.sliceFirstRemainder("foot", "o")); - assertEquals("bc", StringUtils.sliceFirstRemainder("abc", "a")); - assertEquals("cba", StringUtils.sliceFirstRemainder("abcba", "b")); - assertEquals("", StringUtils.sliceFirstRemainder("abc", "c")); - assertEquals("abc", StringUtils.sliceFirstRemainder("abc", "")); - assertEquals("", StringUtils.sliceFirstRemainder("abc", "d")); - } - //----------------------------------------------------------------------- public void testRightPad_StringInt() { assertEquals(null, StringUtils.rightPad(null, 5));