scolebourne    2003/07/19 17:17:30

  Modified:    lang/src/test/org/apache/commons/lang
                        StringUtilsTrimEmptyTest.java StringUtilsTest.java
               lang/src/java/org/apache/commons/lang StringUtils.java
  Log:
  Deprecate deleteSpaces()
  Move delete methods next to replace
  
  Revision  Changes    Path
  1.14      +1 -21     
jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java
  
  Index: StringUtilsTrimEmptyTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StringUtilsTrimEmptyTest.java     20 Jul 2003 00:04:12 -0000      1.13
  +++ StringUtilsTrimEmptyTest.java     20 Jul 2003 00:17:29 -0000      1.14
  @@ -170,26 +170,6 @@
           assertEquals(true, StringUtils.isNotBlank("  foo  "));
       }
   
  -    public void testDeleteSpace() {
  -        assertEquals(null, StringUtils.deleteSpaces(null));
  -        assertEquals("", StringUtils.deleteSpaces(""));
  -        assertEquals("", StringUtils.deleteSpaces("    \t\t\n\n   "));
  -        assertEquals("test", StringUtils.deleteSpaces("t  \t\ne\rs\n\n   \tt"));
  -    }
  -    
  -    public void testDeleteWhitespace() {
  -        assertEquals(null, StringUtils.deleteWhitespace(null));
  -        assertEquals("", StringUtils.deleteWhitespace(""));
  -        assertEquals("", StringUtils.deleteWhitespace("  \u000C  \t\t\u001F\n\n 
\u000B  "));
  -        assertEquals("", StringUtils.deleteWhitespace(StringUtilsTest.WHITESPACE));
  -        assertEquals(StringUtilsTest.NON_WHITESPACE, 
StringUtils.deleteWhitespace(StringUtilsTest.NON_WHITESPACE));
  -        // Note: u-2007 and u-000A both cause problems in the source code
  -        // it should ignore 2007 but delete 000A
  -        assertEquals("\u00A0\u202F", StringUtils.deleteWhitespace("  \u00A0  
\t\t\n\n \u202F  "));
  -        assertEquals("\u00A0\u202F", StringUtils.deleteWhitespace("\u00A0\u202F"));
  -        assertEquals("test", StringUtils.deleteWhitespace("\u000Bt  
\t\n\u0009e\rs\n\n   \tt"));
  -    }
  -
       public void testStrip_String() {
           assertEquals(null, StringUtils.strip(null));
           assertEquals("", StringUtils.strip(""));
  
  
  
  1.31      +73 -21    
jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
  
  Index: StringUtilsTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- StringUtilsTest.java      19 Jul 2003 23:28:23 -0000      1.30
  +++ StringUtilsTest.java      20 Jul 2003 00:17:29 -0000      1.31
  @@ -341,26 +341,78 @@
           }
       }
   
  -    public void testReplaceFunctions() {
  -        assertEquals("replace(String, String, String, int) failed",
  -                     FOO, StringUtils.replace("oo" + FOO, "o", "", 2));
  -        assertEquals("replace(String, String, String) failed",
  -                     "", StringUtils.replace(FOO + FOO + FOO, FOO, ""));
  -        assertEquals("replaceOnce(String, String, String) failed",
  -                     FOO, StringUtils.replaceOnce(FOO + FOO, FOO, ""));
  -        assertEquals("carriage-return replace(String,String,String) failed",
  -                     "test123", StringUtils.replace("test\r1\r2\r3", "\r", ""));
  -
  -        assertEquals("replace(String, String, String) failed",
  -            "FOO", StringUtils.replace("FOO", "", "any"));
  -        assertEquals("replace(String, String, String) failed",
  -            "FOO", StringUtils.replace("FOO", null, "any"));
  -        assertEquals("replace(String, String, String) failed",
  -            "FOO", StringUtils.replace("FOO", "F", null));
  -        assertEquals("replace(String, String, String) failed",
  -            "FOO", StringUtils.replace("FOO", null, null));
  -        assertEquals("replace(String, String, String) failed",
  -            null, StringUtils.replace(null, "", "any"));
  +    public void testDeleteSpace_String() {
  +        assertEquals(null, StringUtils.deleteSpaces(null));
  +        assertEquals("", StringUtils.deleteSpaces(""));
  +        assertEquals("", StringUtils.deleteSpaces("    \t\t\n\n   "));
  +        assertEquals("test", StringUtils.deleteSpaces("t  \t\ne\rs\n\n   \tt"));
  +    }
  +    
  +    public void testDeleteWhitespace_String() {
  +        assertEquals(null, StringUtils.deleteWhitespace(null));
  +        assertEquals("", StringUtils.deleteWhitespace(""));
  +        assertEquals("", StringUtils.deleteWhitespace("  \u000C  \t\t\u001F\n\n 
\u000B  "));
  +        assertEquals("", StringUtils.deleteWhitespace(StringUtilsTest.WHITESPACE));
  +        assertEquals(StringUtilsTest.NON_WHITESPACE, 
StringUtils.deleteWhitespace(StringUtilsTest.NON_WHITESPACE));
  +        // Note: u-2007 and u-000A both cause problems in the source code
  +        // it should ignore 2007 but delete 000A
  +        assertEquals("\u00A0\u202F", StringUtils.deleteWhitespace("  \u00A0  
\t\t\n\n \u202F  "));
  +        assertEquals("\u00A0\u202F", StringUtils.deleteWhitespace("\u00A0\u202F"));
  +        assertEquals("test", StringUtils.deleteWhitespace("\u000Bt  
\t\n\u0009e\rs\n\n   \tt"));
  +    }
  +
  +    public void testReplace_StringStringString() {
  +        assertEquals(null, StringUtils.replace(null, null, null));
  +        assertEquals(null, StringUtils.replace(null, null, "any"));
  +        assertEquals(null, StringUtils.replace(null, "any", null));
  +        assertEquals(null, StringUtils.replace(null, "any", "any"));
  +
  +        assertEquals("", StringUtils.replace("", null, null));
  +        assertEquals("", StringUtils.replace("", null, "any"));
  +        assertEquals("", StringUtils.replace("", "any", null));
  +        assertEquals("", StringUtils.replace("", "any", "any"));
  +
  +        assertEquals("FOO", StringUtils.replace("FOO", "", "any"));
  +        assertEquals("FOO", StringUtils.replace("FOO", null, "any"));
  +        assertEquals("FOO", StringUtils.replace("FOO", "F", null));
  +        assertEquals("FOO", StringUtils.replace("FOO", null, null));
  +
  +        assertEquals("", StringUtils.replace("foofoofoo", "foo", ""));
  +        assertEquals("barbarbar", StringUtils.replace("foofoofoo", "foo", "bar"));
  +        assertEquals("farfarfar", StringUtils.replace("foofoofoo", "oo", "ar"));
  +    }
  +    
  +    public void testReplace_StringStringStringInt() {
  +        assertEquals(null, StringUtils.replace(null, null, null, 2));
  +        assertEquals(null, StringUtils.replace(null, null, "any", 2));
  +        assertEquals(null, StringUtils.replace(null, "any", null, 2));
  +        assertEquals(null, StringUtils.replace(null, "any", "any", 2));
  +
  +        assertEquals("f", StringUtils.replace("oofoo", "o", "", -1));
  +        assertEquals("oofoo", StringUtils.replace("oofoo", "o", "", 0));
  +        assertEquals("ofoo", StringUtils.replace("oofoo", "o", "", 1));
  +        assertEquals("foo", StringUtils.replace("oofoo", "o", "", 2));
  +        assertEquals("fo", StringUtils.replace("oofoo", "o", "", 3));
  +        assertEquals("f", StringUtils.replace("oofoo", "o", "", 4));
  +    }
  +    
  +    public void testReplaceOnce_StringStringString() {
  +        assertEquals(null, StringUtils.replaceOnce(null, null, null));
  +        assertEquals(null, StringUtils.replaceOnce(null, null, "any"));
  +        assertEquals(null, StringUtils.replaceOnce(null, "any", null));
  +        assertEquals(null, StringUtils.replaceOnce(null, "any", "any"));
  +
  +        assertEquals("", StringUtils.replaceOnce("", null, null));
  +        assertEquals("", StringUtils.replaceOnce("", null, "any"));
  +        assertEquals("", StringUtils.replaceOnce("", "any", null));
  +        assertEquals("", StringUtils.replaceOnce("", "any", "any"));
  +
  +        assertEquals("FOO", StringUtils.replaceOnce("FOO", "", "any"));
  +        assertEquals("FOO", StringUtils.replaceOnce("FOO", null, "any"));
  +        assertEquals("FOO", StringUtils.replaceOnce("FOO", "F", null));
  +        assertEquals("FOO", StringUtils.replaceOnce("FOO", null, null));
  +
  +        assertEquals("foofoo", StringUtils.replaceOnce("foofoofoo", "foo", ""));
       }
   
       public void testOverlayString() {
  
  
  
  1.69      +66 -64    
jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- StringUtils.java  20 Jul 2003 00:04:12 -0000      1.68
  +++ StringUtils.java  20 Jul 2003 00:17:29 -0000      1.69
  @@ -250,66 +250,6 @@
           return (str == null ? "" : str.trim());
       }
       
  -    // Delete
  -    //-----------------------------------------------------------------------
  -
  -    /**
  -     * <p>Deletes all 'space' characters from a String as defined by
  -     * [EMAIL PROTECTED] Character#isSpace(char)}.</p>
  -     * 
  -     * <p>This is the only StringUtils method that uses the 
  -     * <code>isSpace</code> definition. You are advised to use
  -     * [EMAIL PROTECTED] #deleteWhitespace(String)} instead as whitespace is much
  -     * better localized.</p>
  -     *
  -     * <pre>
  -     * StringUtils.deleteSpaces(null)           = null
  -     * StringUtils.deleteSpaces("abc")          = "abc"
  -     * StringUtils.deleteSpaces(" \t  abc \n ") = "abc"
  -     * StringUtils.deleteSpaces("ab  c")        = "abc"
  -     * StringUtils.deleteSpaces("a\nb\tc     ") = "abc"
  -     * </pre>
  -     *  
  -     * <p>Spaces are defined as <code>{' ', '\t', '\r', '\n', '\b'}</code>
  -     * in line with the deprecated <code>isSpace</code> method.</p>
  -     *
  -     * @param str  the String to delete spaces from, may be null
  -     * @return the String without 'spaces', <code>null</code> if null String input
  -     */
  -    public static String deleteSpaces(String str) {
  -        if (str == null) {
  -            return null;
  -        }
  -        return CharSetUtils.delete(str, " \t\r\n\b");
  -    }
  -
  -    /**
  -     * <p>Deletes all whitespaces from a String as defined by
  -     * [EMAIL PROTECTED] Character#isWhitespace(char)}.</p>
  -     *
  -     * <pre>
  -     * StringUtils.deleteWhitespace(null)        = null
  -     * StringUtils.deleteWhitespace("abc")       = "abc"
  -     * StringUtils.deleteWhitespace("   abc  ")  = "abc"
  -     * </pre>
  -     *  
  -     * @param str  the String to delete whitespace from, may be null
  -     * @return the String without whitespaces, <code>null</code> if null String 
input
  -     */
  -    public static String deleteWhitespace(String str) {
  -        if (str == null) {
  -            return null;
  -        }
  -        int sz = str.length();
  -        StringBuffer buffer = new StringBuffer(sz);
  -        for (int i = 0; i < sz; i++) {
  -            if (!Character.isWhitespace(str.charAt(i))) {
  -                buffer.append(str.charAt(i));
  -            }
  -        }
  -        return buffer.toString();
  -    }
  -
       // Empty checks
       //-----------------------------------------------------------------------
   
  @@ -1577,11 +1517,73 @@
           return buf.toString();
       }
   
  +    // Delete
  +    //-----------------------------------------------------------------------
  +
  +    /**
  +     * <p>Deletes all 'space' characters from a String as defined by
  +     * [EMAIL PROTECTED] Character#isSpace(char)}.</p>
  +     * 
  +     * <p>This is the only StringUtils method that uses the 
  +     * <code>isSpace</code> definition. You are advised to use
  +     * [EMAIL PROTECTED] #deleteWhitespace(String)} instead as whitespace is much
  +     * better localized.</p>
  +     *
  +     * <pre>
  +     * StringUtils.deleteSpaces(null)           = null
  +     * StringUtils.deleteSpaces("abc")          = "abc"
  +     * StringUtils.deleteSpaces(" \t  abc \n ") = "abc"
  +     * StringUtils.deleteSpaces("ab  c")        = "abc"
  +     * StringUtils.deleteSpaces("a\nb\tc     ") = "abc"
  +     * </pre>
  +     *  
  +     * <p>Spaces are defined as <code>{' ', '\t', '\r', '\n', '\b'}</code>
  +     * in line with the deprecated <code>isSpace</code> method.</p>
  +     *
  +     * @param str  the String to delete spaces from, may be null
  +     * @return the String without 'spaces', <code>null</code> if null String input
  +     * @deprecated Use the better localized [EMAIL PROTECTED] 
#deleteWhitespace(String)}.
  +     *             Method will be removed in Commons Lang 3.0.
  +     */
  +    public static String deleteSpaces(String str) {
  +        if (str == null) {
  +            return null;
  +        }
  +        return CharSetUtils.delete(str, " \t\r\n\b");
  +    }
  +
  +    /**
  +     * <p>Deletes all whitespaces from a String as defined by
  +     * [EMAIL PROTECTED] Character#isWhitespace(char)}.</p>
  +     *
  +     * <pre>
  +     * StringUtils.deleteWhitespace(null)        = null
  +     * StringUtils.deleteWhitespace("abc")       = "abc"
  +     * StringUtils.deleteWhitespace("   abc  ")  = "abc"
  +     * </pre>
  +     *  
  +     * @param str  the String to delete whitespace from, may be null
  +     * @return the String without whitespaces, <code>null</code> if null String 
input
  +     */
  +    public static String deleteWhitespace(String str) {
  +        if (str == null) {
  +            return null;
  +        }
  +        int sz = str.length();
  +        StringBuffer buffer = new StringBuffer(sz);
  +        for (int i = 0; i < sz; i++) {
  +            if (!Character.isWhitespace(str.charAt(i))) {
  +                buffer.append(str.charAt(i));
  +            }
  +        }
  +        return buffer.toString();
  +    }
  +
       // Replacing
       //-----------------------------------------------------------------------
       
       /**
  -     * <p>Replace a String with another String inside a larger String, once.</p>
  +     * <p>Replaces a String with another String inside a larger String, once.</p>
        * 
        * <p>A <code>null</code> reference passed to this method is a no-op.</p>
        * 
  @@ -1606,7 +1608,7 @@
       }
   
       /**
  -     * <p>Replace all occurances of a String within another String.</p>
  +     * <p>Replaces all occurances of a String within another String.</p>
        *
        * <p>A <code>null</code> reference passed to this method is a no-op.</p>
        * 
  @@ -1631,7 +1633,7 @@
       }
   
       /**
  -     * <p>Replace a String with another String inside a larger String,
  +     * <p>Replaces a String with another String inside a larger String,
        * for the first <code>max</code> values of the search String.</p>
        *
        * <p>A <code>null</code> reference passed to this method is a no-op.</p>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to