commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
Date Fri, 27 Sep 2002 06:08:17 GMT
bayard      2002/09/26 23:08:17

  Modified:    lang/src/test/org/apache/commons/lang
                        StringUtilsTrimEmptyTest.java
               lang/src/java/org/apache/commons/lang StringUtils.java
  Log:
  Changed the deleteWhitespace method to delete according to Character.isWhitespce
  Renamed the existing deleteWhitespace functionality to deleteSpaces.
  This is in accordance with Character.isSpace.
  
  Submitted by:	Steve Downey's idea
  
  Revision  Changes    Path
  1.5       +17 -4     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringUtilsTrimEmptyTest.java	21 Jul 2002 20:19:50 -0000	1.4
  +++ StringUtilsTrimEmptyTest.java	27 Sep 2002 06:08:16 -0000	1.5
  @@ -122,13 +122,26 @@
           assertEquals(true, StringUtils.isEmpty(null));
       }
   
  -    public void testDeleteWhitespace() {
  +    public void testDeleteSpace() {
           assertEquals("deleteWhitespace(String) failed",
                        "", StringUtils.deleteWhitespace(""));
           assertEquals("deleteWhitespace(String) failed",
  -                     "", StringUtils.deleteWhitespace("    \t\t\n\n   "));
  +                     "", StringUtils.deleteWhitespace("  \u000C  \t\t\u001F\n\n \u000B
 "));
  +        // Note: u-2007 and u-000A both cause problems in the source code
  +        // it should ignore 2007 but delete 000A
           assertEquals("deleteWhitespace(String) failed",
  -                     "test", StringUtils.deleteWhitespace("t  \t\ne\rs\n\n   \tt"));
  +                     "\u00A0\u202F", StringUtils.deleteWhitespace("  \u00A0  \t\t\n\n \u202F
 "));
  +        assertEquals("deleteWhitespace(String) failed",
  +                     "\u00A0\u202F", StringUtils.deleteWhitespace("\u00A0\u202F"));
  +        assertEquals("deleteWhitespace(String) failed",
  +                     "test", StringUtils.deleteWhitespace("\u000Bt  \t\n\u0009e\rs\n\n
  \tt"));
  +
  +        assertEquals("deleteSpaces(String) failed",
  +                     "", StringUtils.deleteSpaces(""));
  +        assertEquals("deleteSpaces(String) failed",
  +                     "", StringUtils.deleteSpaces("    \t\t\n\n   "));
  +        assertEquals("deleteSpaces(String) failed",
  +                     "test", StringUtils.deleteSpaces("t  \t\ne\rs\n\n   \tt"));
       }
   
       public void testStrip() {
  
  
  
  1.15      +23 -3     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StringUtils.java	27 Sep 2002 05:53:37 -0000	1.14
  +++ StringUtils.java	27 Sep 2002 06:08:16 -0000	1.15
  @@ -119,15 +119,35 @@
       }
   
       /**
  +     * Deletes all 'space' characters from a String.
  +     * Spaces are defined as {' ', '\t', '\r', '\n', '\b'}
  +     * in line with the deprecated Character.isSpace
  +     *
  +     * @param str  String target to delete spaces from
  +     * @return the text without spaces
  +     * @throws NullPointerException
  +     */
  +    public static String deleteSpaces(String str) {
  +        return CharSetUtils.delete(str, " \t\r\n\b");
  +    }
  +
  +    /**
        * Deletes all whitespace from a String.
  -     * Whitespace is defined as {' ', '\t', '\r', '\n', '\b'}
  +     * Whitespace is defined by Character.isWhitespace
        *
        * @param str  String target to delete whitespace from
        * @return the text without whitespace
        * @throws NullPointerException
        */
       public static String deleteWhitespace(String str) {
  -        return CharSetUtils.delete(str, " \t\r\n\b");
  +        StringBuffer buffer = new StringBuffer();
  +        int sz = str.length();
  +        for (int i=0; i<sz; i++) {
  +            if(!Character.isWhitespace(str.charAt(i))) {
  +                buffer.append(str.charAt(i));
  +            }
  +        }
  +        return buffer.toString();
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message