You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2010/06/22 07:44:47 UTC
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
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));
Re: 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
Posted by sebb <se...@gmail.com>.
On 22/06/2010, bayard@apache.org <ba...@apache.org> wrote:
> 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.
That makes it sound like there are large chunks of code, instead of a
single method.
Might be an idea to note the method name, i.e. put:
This product includes software from the Spring Framework,
see: StringUtils.containsWhitespace()
>
> 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));
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org