commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1088505 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/StringUtils.java test/java/org/apache/commons/lang3/StringUtilsTest.java
Date Mon, 04 Apr 2011 08:42:38 GMT
Author: bayard
Date: Mon Apr  4 08:42:38 2011
New Revision: 1088505

URL: http://svn.apache.org/viewvc?rev=1088505&view=rev
Log:
Rolling capitalize and uncapitalize back from (CharSequence) to (String)

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1088505&r1=1088504&r2=1088505&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Mon
Apr  4 08:42:38 2011
@@ -5004,29 +5004,25 @@ public class StringUtils {
      * StringUtils.capitalize("cAt") = "CAt"
      * </pre>
      *
-     * @param cs the String to capitalize, may be null
+     * @param str the String to capitalize, may be null
      * @return the capitalized String, {@code null} if null String input
      * @see org.apache.commons.lang3.text.WordUtils#capitalize(String)
-     * @see #uncapitalize(CharSequence)
+     * @see #uncapitalize(String)
      * @since 2.0
-     * @since 3.0 Changed signature from capitalize(String) to capitalize(CharSequence)
      */
-    public static String capitalize(CharSequence cs) {
-        if (cs == null ) {
-            return null;
-        }
+    public static String capitalize(String str) {
         int strLen;
-        if ((strLen = cs.length()) == 0) {
-            return cs.toString();
+        if (str == null || (strLen = str.length()) == 0) {
+            return str;
         }
         return new StringBuilder(strLen)
-            .append(Character.toTitleCase(cs.charAt(0)))
-            .append(StringUtils.subSequence(cs, 1))
+            .append(Character.toTitleCase(str.charAt(0)))
+            .append(str.substring(1))
             .toString();
     }
 
     /**
-     * <p>Uncapitalizes a CharSequence changing the first letter to title case as
+     * <p>Uncapitalizes a String changing the first letter to title case as
      * per {@link Character#toLowerCase(char)}. No other letters are changed.</p>
      *
      * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#uncapitalize(String)}.
@@ -5039,24 +5035,20 @@ public class StringUtils {
      * StringUtils.uncapitalize("CAT") = "cAT"
      * </pre>
      *
-     * @param cs the String to uncapitalize, may be null
+     * @param str the String to uncapitalize, may be null
      * @return the uncapitalized String, {@code null} if null String input
      * @see org.apache.commons.lang3.text.WordUtils#uncapitalize(String)
-     * @see #capitalize(CharSequence)
+     * @see #capitalize(String)
      * @since 2.0
-     * @since 3.0 Changed signature from uncapitalize(String) to uncapitalize(CharSequence)
      */
-    public static String uncapitalize(CharSequence cs) {
-        if (cs == null ) {
-            return null;
-        }
+    public static String uncapitalize(String str) {
         int strLen;
-        if ((strLen = cs.length()) == 0) {
-            return cs.toString();
+        if (str == null || (strLen = str.length()) == 0) {
+            return str;
         }
         return new StringBuilder(strLen)
-            .append(Character.toLowerCase(cs.charAt(0)))
-            .append(StringUtils.subSequence(cs, 1))
+            .append(Character.toLowerCase(str.charAt(0)))
+            .append(str.substring(1))
             .toString();
     }
 

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=1088505&r1=1088504&r2=1088505&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Mon Apr  4 08:42:38 2011
@@ -119,12 +119,6 @@ public class StringUtilsTest extends Tes
                      "", StringUtils.capitalize("") );
         assertEquals("capitalize(single-char-string) failed",
                 "X", StringUtils.capitalize("x") );
-        assertEquals("capitalize(single-char-string) failed",
-                "X", StringUtils.capitalize(new StringBuilder("x")) );
-        assertEquals("capitalize(single-char-string) failed",
-                "X", StringUtils.capitalize(new StringBuffer("x")) );
-        assertEquals("capitalize(single-char-string) failed",
-                "X", StringUtils.capitalize(CharBuffer.wrap("x")) );
         
         assertEquals("uncapitalize(String) failed",
                      FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP) );
@@ -132,12 +126,6 @@ public class StringUtilsTest extends Tes
                      "", StringUtils.uncapitalize("") );
         assertEquals("uncapitalize(single-char-string) failed",
                 "x", StringUtils.uncapitalize("X") );
-        assertEquals("uncapitalize(single-char-string) failed",
-                "x", StringUtils.uncapitalize(new StringBuilder("X")) );
-        assertEquals("uncapitalize(single-char-string) failed",
-                "x", StringUtils.uncapitalize(new StringBuffer("X")) );
-        assertEquals("uncapitalize(single-char-string) failed",
-                "x", StringUtils.uncapitalize(CharBuffer.wrap("X")) );
                      
         // reflection type of tests: Sentences.
         assertEquals("uncapitalize(capitalize(String)) failed",



Mime
View raw message