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/test/org/apache/commons/lang StringUtilsIsTest.java StringUtilsTest.java
Date Mon, 28 Oct 2002 04:33:30 GMT
bayard      2002/10/27 20:33:30

  Modified:    lang     STATUS.html
               lang/src/java/org/apache/commons/lang StringUtils.java
               lang/src/test/org/apache/commons/lang StringUtilsIsTest.java
                        StringUtilsTest.java
  Log:
  Added isWhitespace, isTrue and uncapitaliseAllWords methods and tests.
  
  Revision  Changes    Path
  1.24      +1 -3      jakarta-commons/lang/STATUS.html
  
  Index: STATUS.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/STATUS.html,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- STATUS.html	27 Oct 2002 19:42:04 -0000	1.23
  +++ STATUS.html	28 Oct 2002 04:33:29 -0000	1.24
  @@ -88,8 +88,6 @@
   <li>CalendarUtils - possible addition of a calendar utility class (from Serge Knystautas)</li>
   <li>CloneUtils - utility class to enable cloning via various different mechanisms.
This code exists in [pattern] at present.</li>
   <li>StringUtils truncateNicely method - A substring with some extra power to choose
where to cut off. It was in Avalon and was added separately to String Taglib from a code submission.
This suggests it may have some commonality. [CODED]</li>
  -<li>StringUtils parseBoolean method - This method is in OSCore's TextUtils and seems
very reusable. It could go in a BooleanUtils if such a need was seen. [CODED]</li>
  -<li>StringUtils uncapitaliseAllWords method - String Taglib has shown that this method
is missing from StringUtils. [CODED]</li>
   <li>StringUtils unescape method - String Taglib has shown that this method is missing
from StringUtils. It would take a String with "\n" in and convert it to the Java character.
unescape and escape should be symmetric. </li>
   <li>ArrayUtils - opinion seems to be that this belongs with [lang] and not [collections]
   <li>GUID and other Identifier generators - these may belong in [util], some code
exists in [pattern] at the moment
  
  
  
  1.21      +72 -1     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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- StringUtils.java	27 Oct 2002 19:42:04 -0000	1.20
  +++ StringUtils.java	28 Oct 2002 04:33:29 -0000	1.21
  @@ -1255,6 +1255,36 @@
           return buffer.toString();
       }
   
  +    /**
  +     * Uncapitalise all the words in a string. Uses
  +     * Character.isWhitespace
  +     * as a separator between words. Null will return null.
  +     *
  +     * @param str  the string to uncapitalise
  +     * @return uncapitalised string
  +     */
  +    public static String uncapitaliseAllWords(String str) {
  +        if (str == null) {
  +            return null;
  +        }
  +        int sz = str.length();
  +        StringBuffer buffer = new StringBuffer(sz);
  +        boolean space = true;
  +        for (int i = 0; i < sz; i++) {
  +            char ch = str.charAt(i);
  +            if (Character.isWhitespace(ch)) {
  +                buffer.append(ch);
  +                space = true;
  +            } else if (space) {
  +                buffer.append(Character.toLowerCase(ch));
  +                space = false;
  +            } else {
  +                buffer.append(ch);
  +            }
  +        }
  +        return buffer.toString();
  +    }
  +
       // Nested extraction
       //--------------------------------------------------------------------------
       
  @@ -1342,6 +1372,27 @@
       }
   
       /**
  +     * Checks if the String contains only whitespace.
  +     * <code>null</code> will return <code>false</code>.  The empty
String
  +     * will return <code>true</code>.
  +     * 
  +     * @param str the String to check
  +     * @return true if only contains whitespace, and is non-null
  +     */
  +    public static boolean isWhitespace(String str) {
  +        if (str == null) {
  +            return false;
  +        }
  +        int sz = str.length();
  +        for (int i = 0; i < sz; i++) {
  +            if ((Character.isWhitespace(str.charAt(i)) == false) ) {
  +                return false;
  +            }
  +        }
  +        return true;
  +    }
  +
  +    /**
        * Checks if the String contains only unicode letters and space (' ').
        * <code>null</code> will return <code>false</code>.  The empty
String
        * will return <code>true</code>.
  @@ -1447,6 +1498,26 @@
               }
           }
           return true;
  +    }
  +
  +    /**
  +     * Checks if the String contains a 'true' value. These are defined 
  +     * as the words 'true', 'on' and 'yes'.
  +     *
  +     * @param str the String to check
  +     * @return true if the string is 'true|on|yes'
  +     */
  +    public static boolean isTrue(String str) {
  +        if("true".equals(str)) {
  +            return true;
  +        } else
  +        if("on".equals(str)) {
  +            return true;
  +        } else
  +        if("yes".equals(str)) {
  +            return true;
  +        }
  +        return false;
       }
   
       // Defaults
  
  
  
  1.2       +24 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsIsTest.java
  
  Index: StringUtilsIsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsIsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringUtilsIsTest.java	19 Jul 2002 03:35:55 -0000	1.1
  +++ StringUtilsIsTest.java	28 Oct 2002 04:33:29 -0000	1.2
  @@ -118,6 +118,29 @@
           assertEquals(false, StringUtils.isAlphanumeric("hkHKHik*khbkuh"));
       }
   
  +    public void testIsWhitespace() {
  +        assertEquals(false, StringUtils.isWhitespace(null));
  +        assertEquals(true, StringUtils.isWhitespace(""));
  +        assertEquals(true, StringUtils.isWhitespace(" "));
  +        assertEquals(true, StringUtils.isWhitespace("\t \n \t"));
  +        assertEquals(false, StringUtils.isWhitespace("\t aa\n \t"));
  +        assertEquals(true, StringUtils.isWhitespace(" "));
  +        assertEquals(false, StringUtils.isWhitespace(" a "));
  +        assertEquals(false, StringUtils.isWhitespace("a  "));
  +        assertEquals(false, StringUtils.isWhitespace("  a"));
  +        assertEquals(false, StringUtils.isWhitespace("aba"));
  +    }
  +
  +    public void testIsTrue() {
  +        assertEquals(false, StringUtils.isTrue(null));
  +        assertEquals(false, StringUtils.isTrue(""));
  +        assertEquals(false, StringUtils.isTrue("off"));
  +        assertEquals(false, StringUtils.isTrue("oof"));
  +        assertEquals(true, StringUtils.isTrue("true"));
  +        assertEquals(true, StringUtils.isTrue("yes"));
  +        assertEquals(true, StringUtils.isTrue("on"));
  +    }
  +
       public void testIsAlphaspace() {
           assertEquals(false, StringUtils.isAlphaSpace(null));
           assertEquals(true, StringUtils.isAlphaSpace(""));
  
  
  
  1.6       +5 -1      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StringUtilsTest.java	19 Sep 2002 07:02:30 -0000	1.5
  +++ StringUtilsTest.java	28 Oct 2002 04:33:29 -0000	1.6
  @@ -123,6 +123,10 @@
                        FOO, StringUtils.uncapitalise(CAP_FOO) );
           assertEquals("uncapitalise(empty-string) failed",
                        "", StringUtils.uncapitalise("") );
  +        assertEquals("uncapitaliseAllWords(String) failed",
  +                     SENTENCE, StringUtils.uncapitaliseAllWords("Foo Bar Baz") );
  +        assertEquals("uncapitaliseAllWords(empty-string) failed",
  +                     "", StringUtils.uncapitaliseAllWords("") );
   
           assertEquals("upperCase(String) failed",
                        "FOO TEST THING", StringUtils.upperCase("fOo test THING") );
  
  
  

--
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