You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Julien HENRY (JIRA)" <ji...@apache.org> on 2010/06/15 15:31:26 UTC

[jira] Created: (LANG-625) Add StringUtils.containsWhitespace(String str)

Add StringUtils.containsWhitespace(String str)
----------------------------------------------

                 Key: LANG-625
                 URL: https://issues.apache.org/jira/browse/LANG-625
             Project: Commons Lang
          Issue Type: New Feature
    Affects Versions: 2.5
            Reporter: Julien HENRY


Please add the new method StringUtils.containsWhitespace(String str). Here is the version in the Spring framework:

/**
	 * Check whether the given CharSequence contains any whitespace characters.
	 * @param str the CharSequence to check (may be <code>null</code>)
	 * @return <code>true</code> if the CharSequence is not empty and
	 * contains at least 1 whitespace character
	 * @see java.lang.Character#isWhitespace
	 */
	public static boolean containsWhitespace(CharSequence str) {
		if (!hasLength(str)) {
			return false;
		}
		int strLen = str.length();
		for (int i = 0; i < strLen; i++) {
			if (Character.isWhitespace(str.charAt(i))) {
				return true;
			}
		}
		return false;
	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (LANG-625) Add StringUtils.containsWhitespace(String str)

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-625?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-625.
------------------------------

    Fix Version/s: 3.0
       Resolution: Fixed

Double checked, and the basic loop is 10 times faster than regex.

Applied code, updated NOTICE to mention there's code from Spring and added an original unit test. 

svn ci -m "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. " NOTICE.txt src/main/java/org/apache/commons/lang3/StringUtils.java src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java 
Sending        NOTICE.txt
Sending        src/main/java/org/apache/commons/lang3/StringUtils.java
Sending        src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Transmitting file data ...
Committed revision 956775.


> Add StringUtils.containsWhitespace(String str)
> ----------------------------------------------
>
>                 Key: LANG-625
>                 URL: https://issues.apache.org/jira/browse/LANG-625
>             Project: Commons Lang
>          Issue Type: New Feature
>    Affects Versions: 2.5
>            Reporter: Julien HENRY
>             Fix For: 3.0
>
>
> Please add the new method StringUtils.containsWhitespace(String str). Here is the version in the Spring framework:
> /**
> 	 * Check whether the given CharSequence contains any whitespace characters.
> 	 * @param str the CharSequence to check (may be <code>null</code>)
> 	 * @return <code>true</code> if the CharSequence is not empty and
> 	 * contains at least 1 whitespace character
> 	 * @see java.lang.Character#isWhitespace
> 	 */
> 	public static boolean containsWhitespace(CharSequence str) {
> 		if (!hasLength(str)) {
> 			return false;
> 		}
> 		int strLen = str.length();
> 		for (int i = 0; i < strLen; i++) {
> 			if (Character.isWhitespace(str.charAt(i))) {
> 				return true;
> 			}
> 		}
> 		return false;
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.