Package com.axelor.common
Class StringUtils
- java.lang.Object
-
- com.axelor.common.StringUtils
-
public final class StringUtils extends Object
This class provides static helper methods forCharSequence
.
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isAscii(char c)
Returnstrue
if the character is in the ASCII charset.static boolean
isAscii(CharSequence text)
Returnstrue
if the text is in the ASCII charset.static boolean
isBlank(CharSequence value)
Check whether the given string value is blank.static boolean
isEmpty(CharSequence value)
Check whether the given string value is empty.static String
normalizeLanguageTag(String languageTag)
Normalizes a language tag to a valid IETF BCP 47 language tag.static boolean
notBlank(CharSequence value)
Check whether the given string value is not blank.static boolean
notEmpty(CharSequence value)
Check whether the given string value is not empty.static String[]
splitToArray(String text, String delimiter)
Split the given text into an array using the given delimiter.static String[]
splitToArray(String text, String delimiter, boolean trimResult, boolean ignoreEmpty)
Split the given text into an array using the given delimiter.static String
stripAccent(CharSequence value)
Remove diacritics (accents) from aCharSequence
.static String
stripIndent(CharSequence text)
Strip the leading indentation from the given text.static String
stripMargin(CharSequence text)
Strip leading whitespace/control characters followed by '|' from every line in the given text.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(CharSequence value)
Check whether the given string value is empty. The value is empty if null or length is 0.- Parameters:
value
- the string value to test- Returns:
- true if empty false otherwise
-
notEmpty
public static boolean notEmpty(CharSequence value)
Check whether the given string value is not empty. The value is empty if null or length is 0.- Parameters:
value
- the string value to test- Returns:
- true if not empty false otherwise
-
isBlank
public static boolean isBlank(CharSequence value)
Check whether the given string value is blank. The value is blank if null or contains white spaces only.- Parameters:
value
- the string value to test- Returns:
- true if empty false otherwise
-
notBlank
public static boolean notBlank(CharSequence value)
Check whether the given string value is not blank. The value is blank if null or contains white spaces only.- Parameters:
value
- the string value to test- Returns:
- true if not empty false otherwise
-
stripAccent
public static String stripAccent(CharSequence value)
Remove diacritics (accents) from aCharSequence
.- Parameters:
value
- the string to be stripped- Returns:
- text with diacritics removed
-
stripIndent
public static String stripIndent(CharSequence text)
Strip the leading indentation from the given text.The line with the least number of leading spaces determines the number to remove. Lines only containing whitespace are ignored when calculating the number of leading spaces to strip.
- Parameters:
text
- the text to strip indent from- Returns:
- stripped text
-
stripMargin
public static String stripMargin(CharSequence text)
Strip leading whitespace/control characters followed by '|' from every line in the given text.- Parameters:
text
- the text to strip the margin from- Returns:
- the stripped String
-
isAscii
public static boolean isAscii(CharSequence text)
Returnstrue
if the text is in the ASCII charset.- Parameters:
text
- the text to check- Returns:
true
if the text is in the ASCII charset;false
otherwise
-
isAscii
public static boolean isAscii(char c)
Returnstrue
if the character is in the ASCII charset.- Parameters:
c
- the character to check- Returns:
true
if the character is in the ASCII charset;false
otherwise
-
splitToArray
public static String[] splitToArray(String text, String delimiter)
Split the given text into an array using the given delimiter.The result parts are trimmed and empty part omitted.
- Parameters:
text
- the text to slipdelimiter
- the delimiter- Returns:
- array of string
-
splitToArray
public static String[] splitToArray(String text, String delimiter, boolean trimResult, boolean ignoreEmpty)
Split the given text into an array using the given delimiter.- Parameters:
text
- the text to slipdelimiter
- the delimitertrimResult
- whether to trim the result partsignoreEmpty
- whether to omit empty part- Returns:
- array of string
-
-