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 WordUtilsTest.java
Date Thu, 03 Jun 2004 03:49:47 GMT
bayard      2004/06/02 20:49:47

  Modified:    lang/src/java/org/apache/commons/lang WordUtils.java
               lang/src/test/org/apache/commons/lang WordUtilsTest.java
  Log:
  and adding an overloaded method for uncapitalize to maintain symmetry
  
  Revision  Changes    Path
  1.12      +31 -8     jakarta-commons/lang/src/java/org/apache/commons/lang/WordUtils.java
  
  Index: WordUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/WordUtils.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- WordUtils.java	3 Jun 2004 03:40:28 -0000	1.11
  +++ WordUtils.java	3 Jun 2004 03:49:47 -0000	1.12
  @@ -369,20 +369,43 @@
        * @see #capitalize(String)
        */
       public static String uncapitalize(String str) {
  -        int strLen;
  -        if (str == null || (strLen = str.length()) == 0) {
  +        return uncapitalize(str, null);
  +    }
  +
  +    public static String uncapitalize(String str, char[] delimiters) {
  +        if (str == null || str.length() == 0) {
               return str;
           }
  +        int strLen = str.length();
  +
  +        int delimitersLen = 0;
  +        if(delimiters != null) {
  +            delimitersLen = delimiters.length;
  +        }
  +
           StringBuffer buffer = new StringBuffer(strLen);
  -        boolean whitespace = true;
  +        boolean uncapitalizeNext = true;
           for (int i = 0; i < strLen; i++) {
               char ch = str.charAt(i);
  -            if (Character.isWhitespace(ch)) {
  +
  +            boolean isDelimiter = false;
  +            if(delimiters == null) {
  +                isDelimiter = Character.isWhitespace(ch);
  +            } else {
  +                for(int j=0; j < delimitersLen; j++) {
  +                    if(ch == delimiters[j]) {
  +                        isDelimiter = true;
  +                        break;
  +                    }
  +                }
  +            }
  +
  +            if (isDelimiter) {
                   buffer.append(ch);
  -                whitespace = true;
  -            } else if (whitespace) {
  +                uncapitalizeNext = true;
  +            } else if (uncapitalizeNext) {
                   buffer.append(Character.toLowerCase(ch));
  -                whitespace = false;
  +                uncapitalizeNext = false;
               } else {
                   buffer.append(ch);
               }
  
  
  
  1.7       +15 -1     jakarta-commons/lang/src/test/org/apache/commons/lang/WordUtilsTest.java
  
  Index: WordUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/WordUtilsTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WordUtilsTest.java	3 Jun 2004 03:40:28 -0000	1.6
  +++ WordUtilsTest.java	3 Jun 2004 03:49:47 -0000	1.7
  @@ -226,6 +226,20 @@
           assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123") );
       }
       
  +    public void testUncapitalizeWithDelimiters_String() {
  +        assertEquals(null, WordUtils.uncapitalize(null, null));
  +        assertEquals("", WordUtils.uncapitalize("", new char[0]));
  +        assertEquals("  ", WordUtils.uncapitalize("  ", new char[0]));
  +        
  +        char[] chars = new char[] { '-', '+', ' ', '@' };
  +        assertEquals("i", WordUtils.uncapitalize("I", chars) );
  +        assertEquals("i", WordUtils.uncapitalize("i", chars) );
  +        assertEquals("i am-here+123", WordUtils.uncapitalize("i am-here+123", chars) );
  +        assertEquals("i+am here-123", WordUtils.uncapitalize("I+Am Here-123", chars) );
  +        assertEquals("i-am+hERE 123", WordUtils.uncapitalize("i-am+HERE 123", chars) );
  +        assertEquals("i aM-hERE+123", WordUtils.uncapitalize("I AM-HERE+123", chars) );
  +    }
  +    
       public void testSwapCase_String() {
           assertEquals(null, WordUtils.swapCase(null));
           assertEquals("", WordUtils.swapCase(""));
  
  
  

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


Mime
View raw message