mirror of https://github.com/alibaba/easyexcel
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.8 KiB
97 lines
2.8 KiB
package com.alibaba.excel.util; |
|
|
|
/** |
|
* String utils |
|
* |
|
* @author jipengfei |
|
*/ |
|
public class StringUtils { |
|
private StringUtils() {} |
|
|
|
/** |
|
* A String for a space character. |
|
*/ |
|
public static final String SPACE = " "; |
|
|
|
/** |
|
* The empty String {@code ""}. |
|
*/ |
|
public static final String EMPTY = ""; |
|
|
|
/** |
|
* <p>Checks if a CharSequence is empty ("") or null.</p> |
|
* |
|
* <pre> |
|
* StringUtils.isEmpty(null) = true |
|
* StringUtils.isEmpty("") = true |
|
* StringUtils.isEmpty(" ") = false |
|
* StringUtils.isEmpty("bob") = false |
|
* StringUtils.isEmpty(" bob ") = false |
|
* </pre> |
|
* |
|
* <p>NOTE: This method changed in Lang version 2.0. |
|
* It no longer trims the CharSequence. |
|
* That functionality is available in isBlank().</p> |
|
* |
|
* @param cs the CharSequence to check, may be null |
|
* @return {@code true} if the CharSequence is empty or null |
|
*/ |
|
public static boolean isEmpty(final CharSequence cs) { |
|
return cs == null || cs.length() == 0; |
|
} |
|
|
|
/** |
|
* <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 |
|
*/ |
|
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; |
|
} |
|
|
|
|
|
/** |
|
* <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p> |
|
* |
|
* <p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p> |
|
* |
|
* <pre> |
|
* StringUtils.isNotBlank(null) = false |
|
* StringUtils.isNotBlank("") = false |
|
* StringUtils.isNotBlank(" ") = false |
|
* StringUtils.isNotBlank("bob") = true |
|
* StringUtils.isNotBlank(" bob ") = true |
|
* </pre> |
|
* |
|
* @param cs the CharSequence to check, may be null |
|
* @return {@code true} if the CharSequence is |
|
* not empty and not null and not whitespace only |
|
* @since 2.0 |
|
* @since 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence) |
|
*/ |
|
public static boolean isNotBlank(final CharSequence cs) { |
|
return !isBlank(cs); |
|
} |
|
|
|
|
|
}
|
|
|