commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r956775 - in /commons/proper/lang/trunk: NOTICE.txt src/main/java/org/apache/commons/lang3/StringUtils.java src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Date Tue, 22 Jun 2010 05:44:47 GMT
Author: bayard
Date: Tue Jun 22 05:44:47 2010
New Revision: 956775

URL: http://svn.apache.org/viewvc?rev=956775&view=rev
Log:
Adding containsWhitespace method per LANG-625. Code comes from the Spring framework, so I've
added such to the NOTICE file. License is Apache License 2.0. Unit test is original. 

Modified:
    commons/proper/lang/trunk/NOTICE.txt
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java

Modified: commons/proper/lang/trunk/NOTICE.txt
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/NOTICE.txt?rev=956775&r1=956774&r2=956775&view=diff
==============================================================================
--- commons/proper/lang/trunk/NOTICE.txt (original)
+++ commons/proper/lang/trunk/NOTICE.txt Tue Jun 22 05:44:47 2010
@@ -3,3 +3,5 @@ Copyright 2001-2010 The Apache Software 
 
 This product includes software developed by
 The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software from the Spring Framework.

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=956775&r1=956774&r2=956775&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Tue
Jun 22 05:44:47 2010
@@ -1347,6 +1347,28 @@ public class StringUtils {
         return false;
     }
 
+    /**
+     * Check whether the given String contains any whitespace characters.
+     * @param str the String to check (may be <code>null</code>)
+     * @return <code>true</code> if the String is not empty and
+     * contains at least 1 whitespace character
+     * @see java.lang.Character#isWhitespace
+     * @since 3.0
+     */
+    // From org.springframework.util.StringUtils, under Apache License 2.0
+    public static boolean containsWhitespace(String str) {
+        if (isEmpty(str)) {
+            return false;
+        }
+        int strLen = str.length();
+        for (int i = 0; i < strLen; i++) {
+            if (Character.isWhitespace(str.charAt(i))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     // IndexOfAny chars
     //-----------------------------------------------------------------------
     /**

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java?rev=956775&r1=956774&r2=956775&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Tue Jun 22 05:44:47 2010
@@ -431,6 +431,16 @@ public class StringUtilsEqualsIndexOfTes
         assertEquals(true, StringUtils.containsOnly(str3, chars3));
     }
 
+    public void testContainsWhitespace() {
+        assertFalse( StringUtils.containsWhitespace("") );
+        assertTrue( StringUtils.containsWhitespace(" ") );
+        assertFalse( StringUtils.containsWhitespace("a") );
+        assertTrue( StringUtils.containsWhitespace("a ") );
+        assertTrue( StringUtils.containsWhitespace(" a") );
+        assertTrue( StringUtils.containsWhitespace("a\t") );
+        assertTrue( StringUtils.containsWhitespace("\n") );
+    }
+
     public void testEquals() {
         assertEquals(true, StringUtils.equals(null, null));
         assertEquals(true, StringUtils.equals(FOO, FOO));



Mime
View raw message