Package com.axelor.common
Class StringUtils
java.lang.Object
com.axelor.common.StringUtils
This class provides static helper methods for
CharSequence
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
isEmpty
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
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
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
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
Remove diacritics (accents) from aCharSequence
.- Parameters:
value
- the string to be stripped- Returns:
- text with diacritics removed
-
stripIndent
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
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
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
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
-
normalizeLanguageTag
Normalizes a language tag to a valid IETF BCP 47 language tag. For example:fr_fr"
will be normalized to"fr-FR"
.- Parameters:
languageTag
- the language tag to normalize- Returns:
- the normalized language tag
-