diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java
index 6ad364b6c..8351b3e82 100644
--- a/src/java/org/apache/commons/lang/StringUtils.java
+++ b/src/java/org/apache/commons/lang/StringUtils.java
@@ -1020,8 +1020,8 @@ public class StringUtils {
/**
*
Checks if String contains a search String irrespective of case,
- * handling null
. This method uses
- * {@link #contains(String, String)}.
+ * handling null
. Case-insensitivity is defined as by
+ * {@link String#equalsIgnoreCase(String)}.
*
* A null
String will return false
.
*
@@ -1045,7 +1045,14 @@ public class StringUtils {
if (str == null || searchStr == null) {
return false;
}
- return contains(str.toUpperCase(), searchStr.toUpperCase());
+ int len = searchStr.length();
+ int max = str.length() - len;
+ for (int i = 0; i <= max; i++) {
+ if (str.regionMatches(true, i, searchStr, 0, len)) {
+ return true;
+ }
+ }
+ return false;
}
// IndexOfAny chars
diff --git a/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java b/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java
index 411e1ee8f..7c160d390 100644
--- a/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.commons.lang;
+import java.util.Locale;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -311,7 +313,41 @@ public class StringUtilsEqualsIndexOfTest extends TestCase {
assertTrue(StringUtils.containsIgnoreCase("xabcz", "ABC"));
}
- //-----------------------------------------------------------------------
+ public void testContainsIgnoreCase_LocaleIndependence() {
+ Locale orig = Locale.getDefault();
+
+ Locale[] locales = { Locale.ENGLISH, new Locale("tr"), Locale.getDefault() };
+
+ String[][] tdata = {
+ { "i", "I" },
+ { "I", "i" },
+ { "\u03C2", "\u03C3" },
+ { "\u03A3", "\u03C2" },
+ { "\u03A3", "\u03C3" },
+ };
+
+ String[][] fdata = {
+ { "\u00DF", "SS" },
+ };
+
+ try {
+ for (int i = 0; i < locales.length; i++) {
+ Locale.setDefault(locales[i]);
+ for (int j = 0; j < tdata.length; j++) {
+ assertTrue(Locale.getDefault() + ": " + j + " " + tdata[j][0] + " " + tdata[j][1], StringUtils
+ .containsIgnoreCase(tdata[j][0], tdata[j][1]));
+ }
+ for (int j = 0; j < fdata.length; j++) {
+ assertFalse(Locale.getDefault() + ": " + j + " " + fdata[j][0] + " " + fdata[j][1], StringUtils
+ .containsIgnoreCase(fdata[j][0], fdata[j][1]));
+ }
+ }
+ } finally {
+ Locale.setDefault(orig);
+ }
+ }
+
+ // -----------------------------------------------------------------------
public void testIndexOfAny_StringStringarray() {
assertEquals(-1, StringUtils.indexOfAny(null, (String[]) null));
assertEquals(-1, StringUtils.indexOfAny(null, FOOBAR_SUB_ARRAY));