Author: niallp
Date: Fri Jun 29 20:25:53 2007
New Revision: 552088
URL: http://svn.apache.org/viewvc?view=rev&rev=552088
Log:
LANG-326 - StringUtils: startsWith / endsWith / startsWithIgnoreCase /
endsWithIgnoreCase / removeStartIgnoreCase / removeEndIgnoreCase methods
Added:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
(with props)
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LangTestSuite.java
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
Modified:
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?view=diff&rev=552088&r1=552087&r2=552088
==============================================================================
---
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
(original)
+++
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
Fri Jun 29 20:25:53 2007
@@ -32,6 +32,10 @@
* - removes leading and trailing whitespace</li>
* <li><b>Equals</b>
* - compares two strings null-safe</li>
+ * <li><b>startsWith</b>
+ * - check if a String starts with a prefix null-safe</li>
+ * <li><b>endsWith</b>
+ * - check if a String ends with a suffix null-safe</li>
* <li><b>IndexOf/LastIndexOf/Contains</b>
* - null-safe index-of checks
* <li><b>IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut</b>
@@ -2982,6 +2986,41 @@
}
/**
+ * <p>Case insensitive removal of a substring if it is at the begining of
a source string,
+ * otherwise returns the source string.</p>
+ *
+ * <p>A <code>null</code> source string will return <code>null</code>.
+ * An empty ("") source string will return the empty string.
+ * A <code>null</code> search string will return the source string.</p>
+ *
+ * <pre>
+ * StringUtils.removeStartIgnoreCase(null, *) = null
+ * StringUtils.removeStartIgnoreCase("", *) = ""
+ * StringUtils.removeStartIgnoreCase(*, null) = *
+ * StringUtils.removeStartIgnoreCase("www.domain.com", "www.") =
"domain.com"
+ * StringUtils.removeStartIgnoreCase("www.domain.com", "WWW.") =
"domain.com"
+ * StringUtils.removeStartIgnoreCase("domain.com", "www.") =
"domain.com"
+ * StringUtils.removeStartIgnoreCase("www.domain.com", "domain") =
"www.domain.com"
+ * StringUtils.removeStartIgnoreCase("abc", "") = "abc"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for (case insensitive) and remove,
may be null
+ * @return the substring with the string removed if found,
+ * <code>null</code> if null String input
+ * @since 2.4
+ */
+ public static String removeStartIgnoreCase(String str, String remove) {
+ if (isEmpty(str) || isEmpty(remove)) {
+ return str;
+ }
+ if (startsWithIgnoreCase(str, remove)){
+ return str.substring(remove.length());
+ }
+ return str;
+ }
+
+ /**
* <p>Removes a substring only if it is at the end of a source string,
* otherwise returns the source string.</p>
*
@@ -3016,6 +3055,40 @@
}
/**
+ * <p>Case insensitive removal of a substring if it is at the end of a
source string,
+ * otherwise returns the source string.</p>
+ *
+ * <p>A <code>null</code> source string will return <code>null</code>.
+ * An empty ("") source string will return the empty string.
+ * A <code>null</code> search string will return the source string.</p>
+ *
+ * <pre>
+ * StringUtils.removeEnd(null, *) = null
+ * StringUtils.removeEnd("", *) = ""
+ * StringUtils.removeEnd(*, null) = *
+ * StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com."
+ * StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
+ * StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
+ * StringUtils.removeEnd("abc", "") = "abc"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for (case insensitive) and remove,
may be null
+ * @return the substring with the string removed if found,
+ * <code>null</code> if null String input
+ * @since 2.4
+ */
+ public static String removeEndIgnoreCase(String str, String remove) {
+ if (isEmpty(str) || isEmpty(remove)) {
+ return str;
+ }
+ if (endsWithIgnoreCase(str, remove)) {
+ return str.substring(0, str.length() - remove.length());
+ }
+ return str;
+ }
+
+ /**
* <p>Removes all occurances of a substring from within the source
string.</p>
*
* <p>A <code>null</code> source string will return <code>null</code>.
@@ -5058,5 +5131,154 @@
return a;
}
*/
+
+ // startsWith
+ //-----------------------------------------------------------------------
+
+ /**
+ * <p>Check if a String starts with a specified prefix.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two
<code>null</code>
+ * references are considered to be equal. The comparison is case
sensitive.</p>
+ *
+ * <pre>
+ * StringUtils.startsWith(null, null) = true
+ * StringUtils.startsWith(null, "abcdef") = false
+ * StringUtils.startsWith("abc", null) = false
+ * StringUtils.startsWith("abc", "abcdef") = true
+ * StringUtils.startsWith("abc", "ABCDEF") = false
+ * </pre>
+ *
+ * @see java.lang.String#startsWith(String)
+ * @param str the String to check, may be null
+ * @param prefix the prefix to find, may be null
+ * @return <code>true</code> if the String starts with the prefix, case
sensitive, or
+ * both <code>null</code>
+ * @since 2.4
+ */
+ public static boolean startsWith(String str, String prefix) {
+ return startsWith(str, prefix, false);
+ }
+
+ /**
+ * <p>Case insensitive check if a String starts with a specified
prefix.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two
<code>null</code>
+ * references are considered to be equal. The comparison is case
insensitive.</p>
+ *
+ * <pre>
+ * StringUtils.startsWithIgnoreCase(null, null) = true
+ * StringUtils.startsWithIgnoreCase(null, "abcdef") = false
+ * StringUtils.startsWithIgnoreCase("abc", null) = false
+ * StringUtils.startsWithIgnoreCase("abc", "abcdef") = true
+ * StringUtils.startsWithIgnoreCase("abc", "ABCDEF") = true
+ * </pre>
+ *
+ * @see java.lang.String#startsWith(String)
+ * @param str the String to check, may be null
+ * @param prefix the prefix to find, may be null
+ * @return <code>true</code> if the String starts with the prefix, case
insensitive, or
+ * both <code>null</code>
+ * @since 2.4
+ */
+ public static boolean startsWithIgnoreCase(String str, String prefix) {
+ return startsWith(str, prefix, true);
+ }
+
+ /**
+ * <p>Check if a String starts with a specified prefix (optionally case
insensitive).</p>
+ *
+ * @see java.lang.String#startsWith(String)
+ * @param str the String to check, may be null
+ * @param prefix the prefix to find, may be null
+ * @param ignoreCase inidicates whether the compare should ignore case
+ * (case insensitive) or not.
+ * @return <code>true</code> if the String starts with the prefix or
+ * both <code>null</code>
+ */
+ private static boolean startsWith(String str, String prefix, boolean
ignoreCase) {
+ if (str == null || prefix == null) {
+ return (str == null && prefix == null);
+ }
+ if (prefix.length() > str.length()) {
+ return false;
+ }
+ return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length());
+ }
+
+ // endsWith
+ //-----------------------------------------------------------------------
+
+ /**
+ * <p>Check if a String ends with a specified suffix.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two
<code>null</code>
+ * references are considered to be equal. The comparison is case
sensitive.</p>
+ *
+ * <pre>
+ * StringUtils.endsWith(null, null) = true
+ * StringUtils.endsWith(null, "abcdef") = false
+ * StringUtils.endsWith("def", null) = false
+ * StringUtils.endsWith("def", "abcdef") = true
+ * StringUtils.endsWith("def", "ABCDEF") = false
+ * </pre>
+ *
+ * @see java.lang.String#endsWith(String)
+ * @param str the String to check, may be null
+ * @param suffix the suffix to find, may be null
+ * @return <code>true</code> if the String ends with the suffix, case
sensitive, or
+ * both <code>null</code>
+ * @since 2.4
+ */
+ public static boolean endsWith(String str, String suffix) {
+ return endsWith(str, suffix, false);
+ }
+
+ /**
+ * <p>Case insensitive check if a String ends with a specified suffix.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two
<code>null</code>
+ * references are considered to be equal. The comparison is case
insensitive.</p>
+ *
+ * <pre>
+ * StringUtils.endsWithIgnoreCase(null, null) = true
+ * StringUtils.endsWithIgnoreCase(null, "abcdef") = false
+ * StringUtils.endsWithIgnoreCase("def", null) = false
+ * StringUtils.endsWithIgnoreCase("def", "abcdef") = true
+ * StringUtils.endsWithIgnoreCase("def", "ABCDEF") = false
+ * </pre>
+ *
+ * @see java.lang.String#endsWith(String)
+ * @param str the String to check, may be null
+ * @param suffix the suffix to find, may be null
+ * @return <code>true</code> if the String ends with the suffix, case
insensitive, or
+ * both <code>null</code>
+ * @since 2.4
+ */
+ public static boolean endsWithIgnoreCase(String str, String suffix) {
+ return endsWith(str, suffix, true);
+ }
+
+ /**
+ * <p>Check if a String ends with a specified suffix (optionally case
insensitive).</p>
+ *
+ * @see java.lang.String#endsWith(String)
+ * @param str the String to check, may be null
+ * @param suffix the suffix to find, may be null
+ * @param ignoreCase inidicates whether the compare should ignore case
+ * (case insensitive) or not.
+ * @return <code>true</code> if the String starts with the prefix or
+ * both <code>null</code>
+ */
+ private static boolean endsWith(String str, String suffix, boolean
ignoreCase) {
+ if (str == null || suffix == null) {
+ return (str == null && suffix == null);
+ }
+ if (suffix.length() > str.length()) {
+ return false;
+ }
+ int strOffset = str.length() - suffix.length();
+ return str.regionMatches(ignoreCase, strOffset, suffix, 0,
suffix.length());
+ }
}
Modified:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LangTestSuite.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LangTestSuite.java?view=diff&rev=552088&r1=552087&r2=552088
==============================================================================
---
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LangTestSuite.java
(original)
+++
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/LangTestSuite.java
Fri Jun 29 20:25:53 2007
@@ -79,6 +79,7 @@
suite.addTest(StringUtilsSubstringTest.suite());
suite.addTest(StringUtilsEqualsIndexOfTest.suite());
suite.addTest(StringUtilsIsTest.suite());
+ suite.addTest(StringUtilsStartsEndsWithTest.suite());
suite.addTest(StringEscapeUtilsTest.suite());
suite.addTest(SystemUtilsTest.suite());
suite.addTest(UnhandledExceptionTest.suite());
Added:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java?view=auto&rev=552088
==============================================================================
---
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
(added)
+++
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
Fri Jun 29 20:25:53 2007
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Unit tests [EMAIL PROTECTED] org.apache.commons.lang.StringUtils} -
StartsWith/EndsWith methods
+ *
+ * @version $Id$
+ */
+public class StringUtilsStartsEndsWithTest extends TestCase {
+ private static final String foo = "foo";
+ private static final String bar = "bar";
+ private static final String foobar = "foobar";
+ private static final String FOO = "FOO";
+ private static final String BAR = "BAR";
+ private static final String FOOBAR = "FOOBAR";
+
+ public StringUtilsStartsEndsWithTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(StringUtilsStartsEndsWithTest.class);
+ suite.setName("StringUtilsStartsEndsWith Tests");
+ return suite;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Test StringUtils.startsWith()
+ */
+ public void testStartsWith() {
+ assertTrue("startsWith(null, null)", StringUtils.startsWith(null,
(String)null));
+ assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR,
(String)null));
+ assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null,
FOO));
+ assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR,
""));
+
+ assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar,
foo));
+ assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR,
FOO));
+ assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar,
FOO));
+ assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR,
foo));
+
+ assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo,
foobar));
+ assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar,
foobar));
+
+ assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar,
bar));
+ assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR,
BAR));
+ assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar,
BAR));
+ assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR,
bar));
+ }
+
+ /**
+ * Test StringUtils.testStartsWithIgnoreCase()
+ */
+ public void testStartsWithIgnoreCase() {
+ assertTrue("startsWithIgnoreCase(null, null)",
StringUtils.startsWithIgnoreCase(null, (String)null));
+ assertFalse("startsWithIgnoreCase(FOOBAR, null)",
StringUtils.startsWithIgnoreCase(FOOBAR, (String)null));
+ assertFalse("startsWithIgnoreCase(null, FOO)",
StringUtils.startsWithIgnoreCase(null, FOO));
+ assertTrue("startsWithIgnoreCase(FOOBAR, \"\")",
StringUtils.startsWithIgnoreCase(FOOBAR, ""));
+
+ assertTrue("startsWithIgnoreCase(foobar, foo)",
StringUtils.startsWithIgnoreCase(foobar, foo));
+ assertTrue("startsWithIgnoreCase(FOOBAR, FOO)",
StringUtils.startsWithIgnoreCase(FOOBAR, FOO));
+ assertTrue("startsWithIgnoreCase(foobar, FOO)",
StringUtils.startsWithIgnoreCase(foobar, FOO));
+ assertTrue("startsWithIgnoreCase(FOOBAR, foo)",
StringUtils.startsWithIgnoreCase(FOOBAR, foo));
+
+ assertFalse("startsWithIgnoreCase(foo, foobar)",
StringUtils.startsWithIgnoreCase(foo, foobar));
+ assertFalse("startsWithIgnoreCase(foo, foobar)",
StringUtils.startsWithIgnoreCase(bar, foobar));
+
+ assertFalse("startsWithIgnoreCase(foobar, bar)",
StringUtils.startsWithIgnoreCase(foobar, bar));
+ assertFalse("startsWithIgnoreCase(FOOBAR, BAR)",
StringUtils.startsWithIgnoreCase(FOOBAR, BAR));
+ assertFalse("startsWithIgnoreCase(foobar, BAR)",
StringUtils.startsWithIgnoreCase(foobar, BAR));
+ assertFalse("startsWithIgnoreCase(FOOBAR, bar)",
StringUtils.startsWithIgnoreCase(FOOBAR, bar));
+ }
+
+
+ /**
+ * Test StringUtils.endsWith()
+ */
+ public void testEndsWith() {
+ assertTrue("endsWith(null, null)", StringUtils.endsWith(null,
(String)null));
+ assertFalse("endsWith(FOOBAR, null)", StringUtils.endsWith(FOOBAR,
(String)null));
+ assertFalse("endsWith(null, FOO)", StringUtils.endsWith(null, FOO));
+ assertTrue("endsWith(FOOBAR, \"\")", StringUtils.endsWith(FOOBAR,
""));
+
+ assertFalse("endsWith(foobar, foo)", StringUtils.endsWith(foobar,
foo));
+ assertFalse("endsWith(FOOBAR, FOO)", StringUtils.endsWith(FOOBAR,
FOO));
+ assertFalse("endsWith(foobar, FOO)", StringUtils.endsWith(foobar,
FOO));
+ assertFalse("endsWith(FOOBAR, foo)", StringUtils.endsWith(FOOBAR,
foo));
+
+ assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(foo,
foobar));
+ assertFalse("endsWith(foo, foobar)", StringUtils.endsWith(bar,
foobar));
+
+ assertTrue("endsWith(foobar, bar)", StringUtils.endsWith(foobar,
bar));
+ assertTrue("endsWith(FOOBAR, BAR)", StringUtils.endsWith(FOOBAR,
BAR));
+ assertFalse("endsWith(foobar, BAR)", StringUtils.endsWith(foobar,
BAR));
+ assertFalse("endsWith(FOOBAR, bar)", StringUtils.endsWith(FOOBAR,
bar));
+ }
+
+ /**
+ * Test StringUtils.endsWithIgnoreCase()
+ */
+ public void testEndsWithIgnoreCase() {
+ assertTrue("endsWithIgnoreCase(null, null)",
StringUtils.endsWithIgnoreCase(null, (String)null));
+ assertFalse("endsWithIgnoreCase(FOOBAR, null)",
StringUtils.endsWithIgnoreCase(FOOBAR, (String)null));
+ assertFalse("endsWithIgnoreCase(null, FOO)",
StringUtils.endsWithIgnoreCase(null, FOO));
+ assertTrue("endsWithIgnoreCase(FOOBAR, \"\")",
StringUtils.endsWithIgnoreCase(FOOBAR, ""));
+
+ assertFalse("endsWithIgnoreCase(foobar, foo)",
StringUtils.endsWithIgnoreCase(foobar, foo));
+ assertFalse("endsWithIgnoreCase(FOOBAR, FOO)",
StringUtils.endsWithIgnoreCase(FOOBAR, FOO));
+ assertFalse("endsWithIgnoreCase(foobar, FOO)",
StringUtils.endsWithIgnoreCase(foobar, FOO));
+ assertFalse("endsWithIgnoreCase(FOOBAR, foo)",
StringUtils.endsWithIgnoreCase(FOOBAR, foo));
+
+ assertFalse("endsWithIgnoreCase(foo, foobar)",
StringUtils.endsWithIgnoreCase(foo, foobar));
+ assertFalse("endsWithIgnoreCase(foo, foobar)",
StringUtils.endsWithIgnoreCase(bar, foobar));
+
+ assertTrue("endsWithIgnoreCase(foobar, bar)",
StringUtils.endsWithIgnoreCase(foobar, bar));
+ assertTrue("endsWithIgnoreCase(FOOBAR, BAR)",
StringUtils.endsWithIgnoreCase(FOOBAR, BAR));
+ assertTrue("endsWithIgnoreCase(foobar, BAR)",
StringUtils.endsWithIgnoreCase(foobar, BAR));
+ assertTrue("endsWithIgnoreCase(FOOBAR, bar)",
StringUtils.endsWithIgnoreCase(FOOBAR, bar));
+ }
+
+}
Propchange:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsStartsEndsWithTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java?view=diff&rev=552088&r1=552087&r2=552088
==============================================================================
---
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
(original)
+++
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
Fri Jun 29 20:25:53 2007
@@ -1510,6 +1510,27 @@
assertEquals(StringUtils.removeStart("domain.com", ""), "domain.com");
assertEquals(StringUtils.removeStart("domain.com", null),
"domain.com");
}
+
+ public void testRemoveStartIgnoreCase() {
+ // StringUtils.removeStart("", *) = ""
+ assertNull("removeStartIgnoreCase(null, null)",
StringUtils.removeStartIgnoreCase(null, null));
+ assertNull("removeStartIgnoreCase(null, \"\")",
StringUtils.removeStartIgnoreCase(null, ""));
+ assertNull("removeStartIgnoreCase(null, \"a\")",
StringUtils.removeStartIgnoreCase(null, "a"));
+
+ // StringUtils.removeStart(*, null) = *
+ assertEquals("removeStartIgnoreCase(\"\", null)",
StringUtils.removeStartIgnoreCase("", null), "");
+ assertEquals("removeStartIgnoreCase(\"\", \"\")",
StringUtils.removeStartIgnoreCase("", ""), "");
+ assertEquals("removeStartIgnoreCase(\"\", \"a\")",
StringUtils.removeStartIgnoreCase("", "a"), "");
+
+ // All others:
+ assertEquals("removeStartIgnoreCase(\"www.domain.com\", \"www.\")",
StringUtils.removeStartIgnoreCase("www.domain.com", "www."), "domain.com");
+ assertEquals("removeStartIgnoreCase(\"domain.com\", \"www.\")",
StringUtils.removeStartIgnoreCase("domain.com", "www."), "domain.com");
+ assertEquals("removeStartIgnoreCase(\"domain.com\", \"\")",
StringUtils.removeStartIgnoreCase("domain.com", ""), "domain.com");
+ assertEquals("removeStartIgnoreCase(\"domain.com\", null)",
StringUtils.removeStartIgnoreCase("domain.com", null), "domain.com");
+
+ // Case insensitive:
+ assertEquals("removeStartIgnoreCase(\"www.domain.com\", \"WWW.\")",
StringUtils.removeStartIgnoreCase("www.domain.com", "WWW."), "domain.com");
+ }
public void testRemoveEnd() {
// StringUtils.removeEnd("", *) = ""
@@ -1528,6 +1549,28 @@
assertEquals(StringUtils.removeEnd("www.domain", ".com"),
"www.domain");
assertEquals(StringUtils.removeEnd("domain.com", ""), "domain.com");
assertEquals(StringUtils.removeEnd("domain.com", null), "domain.com");
+ }
+
+ public void testRemoveEndIgnoreCase() {
+ // StringUtils.removeEndIgnoreCase("", *) = ""
+ assertNull("removeEndIgnoreCase(null, null)",
StringUtils.removeEndIgnoreCase(null, null));
+ assertNull("removeEndIgnoreCase(null, \"\")",
StringUtils.removeEndIgnoreCase(null, ""));
+ assertNull("removeEndIgnoreCase(null, \"a\")",
StringUtils.removeEndIgnoreCase(null, "a"));
+
+ // StringUtils.removeEnd(*, null) = *
+ assertEquals("removeEndIgnoreCase(\"\", null)",
StringUtils.removeEndIgnoreCase("", null), "");
+ assertEquals("removeEndIgnoreCase(\"\", \"\")",
StringUtils.removeEndIgnoreCase("", ""), "");
+ assertEquals("removeEndIgnoreCase(\"\", \"a\")",
StringUtils.removeEndIgnoreCase("", "a"), "");
+
+ // All others:
+ assertEquals("removeEndIgnoreCase(\"www.domain.com.\", \".com\")",
StringUtils.removeEndIgnoreCase("www.domain.com.", ".com"), "www.domain.com.");
+ assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".com\")",
StringUtils.removeEndIgnoreCase("www.domain.com", ".com"), "www.domain");
+ assertEquals("removeEndIgnoreCase(\"www.domain\", \".com\")",
StringUtils.removeEndIgnoreCase("www.domain", ".com"), "www.domain");
+ assertEquals("removeEndIgnoreCase(\"domain.com\", \"\")",
StringUtils.removeEndIgnoreCase("domain.com", ""), "domain.com");
+ assertEquals("removeEndIgnoreCase(\"domain.com\", null)",
StringUtils.removeEndIgnoreCase("domain.com", null), "domain.com");
+
+ // Case insensitive:
+ assertEquals("removeEndIgnoreCase(\"www.domain.com\", \".com\")",
StringUtils.removeEndIgnoreCase("www.domain.com", ".COM"), "www.domain");
}
public void testRemove_String() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]