Skip to content

Commit

Permalink
fixes networknt#180 add isBlank to StringUtil in utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Mar 21, 2018
1 parent efe30ca commit 0264da9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion utility/src/main/java/com/networknt/utility/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,34 @@ public static String rightPad(final String str, final int size, String padStr) {
}
}


/**
* <p>Checks if a CharSequence is empty (""), null or whitespace only.</p>
*
* <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
*
* <pre>
* StringUtils.isBlank(null) = true
* StringUtils.isBlank("") = true
* StringUtils.isBlank(" ") = true
* StringUtils.isBlank("bob") = false
* StringUtils.isBlank(" bob ") = false
* </pre>
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is null, empty or whitespace only
* @since 2.0
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
*/
public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
}

0 comments on commit 0264da9

Please sign in to comment.