commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r611528 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/StringUtils.java test/org/apache/commons/lang/StringUtilsTest.java
Date Sun, 13 Jan 2008 03:46:29 GMT
Author: mbenson
Date: Sat Jan 12 19:46:28 2008
New Revision: 611528

URL: http://svn.apache.org/viewvc?rev=611528&view=rev
Log:
[LANG-192] API improvements

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=611528&r1=611527&r2=611528&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 Jan 12
19:46:28 2008
@@ -2612,15 +2612,15 @@
      * <code>java.lang.Character.getType(char)</code>. Groups of contiguous
      * characters of the same type are returned as complete tokens. 
      * <pre>
-     * StringUtils.splitByCamelCase(null)         = null
-     * StringUtils.splitByCamelCase("")           = []
-     * StringUtils.splitByCamelCase("ab de fg")   = ["ab", " ", "de", " ", "fg"]
-     * StringUtils.splitByCamelCase("ab   de fg") = ["ab", "   ", "de", " ", "fg"]
-     * StringUtils.splitByCamelCase("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
-     * StringUtils.splitByCamelCase("number5")   = ["number", "5"]
-     * StringUtils.splitByCamelCase("fooBar")     = ["foo", "B", "ar"]
-     * StringUtils.splitByCamelCase("foo200Bar")  = ["foo", "200", "B", "ar"]
-     * StringUtils.splitByCamelCase("ASFRules")   = ["ASFR", "ules"]
+     * StringUtils.splitByCharacterType(null)         = null
+     * StringUtils.splitByCharacterType("")           = []
+     * StringUtils.splitByCharacterType("ab de fg")   = ["ab", " ", "de", " ", "fg"]
+     * StringUtils.splitByCharacterType("ab   de fg") = ["ab", "   ", "de", " ", "fg"]
+     * StringUtils.splitByCharacterType("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
+     * StringUtils.splitByCharacterType("number5")    = ["number", "5"]
+     * StringUtils.splitByCharacterType("fooBar")     = ["foo", "B", "ar"]
+     * StringUtils.splitByCharacterType("foo200Bar")  = ["foo", "200", "B", "ar"]
+     * StringUtils.splitByCharacterType("ASFRules")   = ["ASFR", "ules"]
      * </pre>
      * @param str the String to split, may be <code>null</code>
      * @return an array of parsed Strings, <code>null</code> if null String input
@@ -2634,28 +2634,45 @@
      * <p>Splits a String by Character type as returned by
      * <code>java.lang.Character.getType(char)</code>. Groups of contiguous
      * characters of the same type are returned as complete tokens, with the
+     * following exception: the character of type
+     * <code>Character.UPPERCASE_LETTER</code>, if any, immediately
+     * preceding a token of type <code>Character.LOWERCASE_LETTER</code>
+     * will belong to the following token rather than to the preceding, if any,
+     * <code>Character.UPPERCASE_LETTER</code> token. 
+     * <pre>
+     * StringUtils.splitByCharacterTypeCamelCase(null)         = null
+     * StringUtils.splitByCharacterTypeCamelCase("")           = []
+     * StringUtils.splitByCharacterTypeCamelCase("ab de fg")   = ["ab", " ", "de", " ", "fg"]
+     * StringUtils.splitByCharacterTypeCamelCase("ab   de fg") = ["ab", "   ", "de", " ",
"fg"]
+     * StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
+     * StringUtils.splitByCharacterTypeCamelCase("number5")    = ["number", "5"]
+     * StringUtils.splitByCharacterTypeCamelCase("fooBar")     = ["foo", "Bar"]
+     * StringUtils.splitByCharacterTypeCamelCase("foo200Bar")  = ["foo", "200", "Bar"]
+     * StringUtils.splitByCharacterTypeCamelCase("ASFRules")   = ["ASF", "Rules"]
+     * </pre>
+     * @param str the String to split, may be <code>null</code>
+     * @return an array of parsed Strings, <code>null</code> if null String input
+     * @since 2.4
+     */
+    public static String[] splitByCharacterTypeCamelCase(String str) {
+        return splitByCharacterType(str, true);
+    }
+
+    /**
+     * <p>Splits a String by Character type as returned by
+     * <code>java.lang.Character.getType(char)</code>. Groups of contiguous
+     * characters of the same type are returned as complete tokens, with the
      * following exception: if <code>camelCase</code> is <code>true</code>,
      * the character of type <code>Character.UPPERCASE_LETTER</code>, if any,
      * immediately preceding a token of type <code>Character.LOWERCASE_LETTER</code>
      * will belong to the following token rather than to the preceding, if any,
      * <code>Character.UPPERCASE_LETTER</code> token. 
-     * <pre>
-     * StringUtils.splitByCamelCase(null)         = null
-     * StringUtils.splitByCamelCase("")           = []
-     * StringUtils.splitByCamelCase("ab de fg")   = ["ab", " ", "de", " ", "fg"]
-     * StringUtils.splitByCamelCase("ab   de fg") = ["ab", "   ", "de", " ", "fg"]
-     * StringUtils.splitByCamelCase("ab:cd:ef")   = ["ab", ":", "cd", ":", "ef"]
-     * StringUtils.splitByCamelCase("number5")   = ["number", "5"]
-     * StringUtils.splitByCamelCase("fooBar")     = ["foo", "Bar"]
-     * StringUtils.splitByCamelCase("foo200Bar")  = ["foo", "200", "Bar"]
-     * StringUtils.splitByCamelCase("ASFRules")   = ["ASF", "Rules"]
-     * </pre>
      * @param str the String to split, may be <code>null</code>
      * @param camelCase whether to use so-called "camel-case" for letter types
      * @return an array of parsed Strings, <code>null</code> if null String input
      * @since 2.4
      */
-    public static String[] splitByCharacterType(String str, boolean camelCase) {
+    private static String[] splitByCharacterType(String str, boolean camelCase) {
         if (str == null) {
             return null;
         }

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=611528&r1=611527&r2=611528&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 Jan
12 19:46:28 2008
@@ -851,52 +851,53 @@
     public void testSplitByCharacterType() {
         assertNull(StringUtils.splitByCharacterType(null));
         assertEquals(0, StringUtils.splitByCharacterType("").length);
-        assertNull(StringUtils.splitByCharacterType(null, true));
-        assertEquals(0, StringUtils.splitByCharacterType("", true).length);
-
-        final boolean camelCase = true;
-
-        assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
-                "fg" }, StringUtils.splitByCharacterType("ab de fg")));
-
+        
         assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
-                "fg" }, StringUtils.splitByCharacterType("ab de fg", camelCase)));
-
-        assertTrue(ArrayUtils.isEquals(new String[] { "ab", "   ", "de", " ",
-                "fg" }, StringUtils.splitByCharacterType("ab   de fg")));
-
+        "fg" }, StringUtils.splitByCharacterType("ab de fg")));
+        
         assertTrue(ArrayUtils.isEquals(new String[] { "ab", "   ", "de", " ",
-                "fg" }, StringUtils.splitByCharacterType("ab   de fg", camelCase)));
-
-        assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
-                "ef" }, StringUtils.splitByCharacterType("ab:cd:ef")));
-
+        "fg" }, StringUtils.splitByCharacterType("ab   de fg")));
+        
         assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
-                "ef" }, StringUtils.splitByCharacterType("ab:cd:ef", camelCase)));
+        "ef" }, StringUtils.splitByCharacterType("ab:cd:ef")));
         
         assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
                 StringUtils.splitByCharacterType("number5")));
         
-        assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
-                StringUtils.splitByCharacterType("number5", camelCase)));
-
         assertTrue(ArrayUtils.isEquals(new String[] { "foo", "B", "ar" },
                 StringUtils.splitByCharacterType("fooBar")));
-
-        assertTrue(ArrayUtils.isEquals(new String[] { "foo", "Bar" },
-                StringUtils.splitByCharacterType("fooBar", camelCase)));
-
+        
         assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "B", "ar" },
                 StringUtils.splitByCharacterType("foo200Bar")));
-
-        assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "Bar" },
-                StringUtils.splitByCharacterType("foo200Bar", camelCase)));
-
+        
         assertTrue(ArrayUtils.isEquals(new String[] { "ASFR", "ules" },
                 StringUtils.splitByCharacterType("ASFRules")));
+    }
+    
+    public void testSplitByCharacterTypeCamelCase() {
+        assertNull(StringUtils.splitByCharacterTypeCamelCase(null));
+        assertEquals(0, StringUtils.splitByCharacterTypeCamelCase("").length);
+
+        assertTrue(ArrayUtils.isEquals(new String[] { "ab", " ", "de", " ",
+                "fg" }, StringUtils.splitByCharacterTypeCamelCase("ab de fg")));
+
+        assertTrue(ArrayUtils.isEquals(new String[] { "ab", "   ", "de", " ",
+                "fg" }, StringUtils.splitByCharacterTypeCamelCase("ab   de fg")));
+
+        assertTrue(ArrayUtils.isEquals(new String[] { "ab", ":", "cd", ":",
+                "ef" }, StringUtils.splitByCharacterTypeCamelCase("ab:cd:ef")));
+        
+        assertTrue(ArrayUtils.isEquals(new String[] { "number", "5" },
+                StringUtils.splitByCharacterTypeCamelCase("number5")));
+
+        assertTrue(ArrayUtils.isEquals(new String[] { "foo", "Bar" },
+                StringUtils.splitByCharacterTypeCamelCase("fooBar")));
+
+        assertTrue(ArrayUtils.isEquals(new String[] { "foo", "200", "Bar" },
+                StringUtils.splitByCharacterTypeCamelCase("foo200Bar")));
 
         assertTrue(ArrayUtils.isEquals(new String[] { "ASF", "Rules" },
-                StringUtils.splitByCharacterType("ASFRules", camelCase)));
+                StringUtils.splitByCharacterTypeCamelCase("ASFRules")));
     }
 
     public void testDeprecatedDeleteSpace_String() {



Mime
View raw message