Author: bayard
Date: Sat May 10 21:52:10 2008
New Revision: 655239
URL: http://svn.apache.org/viewvc?rev=655239&view=rev
Log:
Adding Locale overloads for toUpperCase and toLowerCase as provided by Benjamin
Bentmann in LANG-430
Modified:
commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringUtils.java
commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.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=655239&r1=655238&r2=655239&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
Sat May 10 21:52:10 2008
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
/**
* <p>Operations on [EMAIL PROTECTED] java.lang.String} that are
@@ -4708,6 +4709,11 @@
* StringUtils.upperCase("aBc") = "ABC"
* </pre>
*
+ * <p><strong>Note:</strong> As described in the documentation for [EMAIL
PROTECTED] String#toUpperCase()},
+ * the result of this method is affected by the current locale.
+ * For platform-independent case transformations, the method [EMAIL
PROTECTED] #lowerCase(String, Locale)}
+ * should be used with a specific locale (e.g. [EMAIL PROTECTED]
Locale#ENGLISH}).</p>
+ *
* @param str the String to upper case, may be null
* @return the upper cased String, <code>null</code> if null String input
*/
@@ -4719,6 +4725,29 @@
}
/**
+ * <p>Converts a String to upper case as per [EMAIL PROTECTED]
String#toUpperCase(Locale)}.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.</p>
+ *
+ * <pre>
+ * StringUtils.upperCase(null, Locale.ENGLISH) = null
+ * StringUtils.upperCase("", Locale.ENGLISH) = ""
+ * StringUtils.upperCase("aBc", Locale.ENGLISH) = "ABC"
+ * </pre>
+ *
+ * @param str the String to upper case, may be null
+ * @param locale the locale that defines the case transformation rules,
must not be null
+ * @return the upper cased String, <code>null</code> if null String input
+ * @since 3.0
+ */
+ public static String upperCase(String str, Locale locale) {
+ if (str == null) {
+ return null;
+ }
+ return str.toUpperCase(locale);
+ }
+
+ /**
* <p>Converts a String to lower case as per [EMAIL PROTECTED]
String#toLowerCase()}.</p>
*
* <p>A <code>null</code> input String returns <code>null</code>.</p>
@@ -4729,6 +4758,11 @@
* StringUtils.lowerCase("aBc") = "abc"
* </pre>
*
+ * <p><strong>Note:</strong> As described in the documentation for [EMAIL
PROTECTED] String#toLowerCase()},
+ * the result of this method is affected by the current locale.
+ * For platform-independent case transformations, the method [EMAIL
PROTECTED] #lowerCase(String, Locale)}
+ * should be used with a specific locale (e.g. [EMAIL PROTECTED]
Locale#ENGLISH}).</p>
+ *
* @param str the String to lower case, may be null
* @return the lower cased String, <code>null</code> if null String input
*/
@@ -4740,6 +4774,29 @@
}
/**
+ * <p>Converts a String to lower case as per [EMAIL PROTECTED]
String#toLowerCase(Locale)}.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.</p>
+ *
+ * <pre>
+ * StringUtils.lowerCase(null, Locale.ENGLISH) = null
+ * StringUtils.lowerCase("", Locale.ENGLISH) = ""
+ * StringUtils.lowerCase("aBc", Locale.ENGLISH) = "abc"
+ * </pre>
+ *
+ * @param str the String to lower case, may be null
+ * @param locale the locale that defines the case transformation rules,
must not be null
+ * @return the lower cased String, <code>null</code> if null String input
+ * @since 3.0
+ */
+ public static String lowerCase(String str, Locale locale) {
+ if (str == null) {
+ return null;
+ }
+ return str.toLowerCase(locale);
+ }
+
+ /**
* <p>Capitalizes a String changing the first letter to title case as
* per [EMAIL PROTECTED] Character#toTitleCase(char)}. No other letters
are changed.</p>
*
Modified:
commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java?rev=655239&r1=655238&r2=655239&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
(original)
+++
commons/proper/lang/trunk/src/test/org/apache/commons/lang/StringUtilsTest.java
Sat May 10 21:52:10 2008
@@ -22,6 +22,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Locale;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -127,7 +128,9 @@
//-----------------------------------------------------------------------
public void testCaseFunctions() {
assertEquals(null, StringUtils.upperCase(null));
+ assertEquals(null, StringUtils.upperCase(null, Locale.ENGLISH));
assertEquals(null, StringUtils.lowerCase(null));
+ assertEquals(null, StringUtils.lowerCase(null, Locale.ENGLISH));
assertEquals(null, StringUtils.capitalize(null));
assertEquals(null, StringUtils.uncapitalise(null));
assertEquals(null, StringUtils.uncapitalize(null));
@@ -185,7 +188,15 @@
"foo test thing", StringUtils.lowerCase("fOo test THING")
);
assertEquals("lowerCase(empty-string) failed",
"", StringUtils.lowerCase("") );
-
+
+ assertEquals("upperCase(String, Locale) failed",
+ "FOO TEST THING", StringUtils.upperCase("fOo test THING",
Locale.ENGLISH) );
+ assertEquals("upperCase(empty-string, Locale) failed",
+ "", StringUtils.upperCase("", Locale.ENGLISH) );
+ assertEquals("lowerCase(String, Locale) failed",
+ "foo test thing", StringUtils.lowerCase("fOo test THING",
Locale.ENGLISH) );
+ assertEquals("lowerCase(empty-string, Locale) failed",
+ "", StringUtils.lowerCase("", Locale.ENGLISH) );
}
public void testSwapCase_String() {