Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 71895 invoked from network); 22 Oct 2009 05:46:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Oct 2009 05:46:58 -0000 Received: (qmail 38696 invoked by uid 500); 22 Oct 2009 05:46:58 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 38611 invoked by uid 500); 22 Oct 2009 05:46:57 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 38602 invoked by uid 99); 22 Oct 2009 05:46:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Oct 2009 05:46:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Oct 2009 05:46:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F345A238898D; Thu, 22 Oct 2009 05:46:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r828317 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/StringUtils.java test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java Date: Thu, 22 Oct 2009 05:46:33 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091022054633.F345A238898D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Thu Oct 22 05:46:33 2009 New Revision: 828317 URL: http://svn.apache.org/viewvc?rev=828317&view=rev Log: Applying the final part of Benjamin Bentmann's patch to LANG-432, improving our handling of case-insensitive Strings Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java?rev=828317&r1=828316&r2=828317&view=diff ============================================================================== --- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java (original) +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java Thu Oct 22 05:46:33 2009 @@ -1020,8 +1020,8 @@ /** *

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 @@ 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 Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java?rev=828317&r1=828316&r2=828317&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java (original) +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsEqualsIndexOfTest.java Thu Oct 22 05:46:33 2009 @@ -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 @@ 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));