public final class StringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Color |
asColorHexadecimal(String token)
Returns a Color parsed from the given RGB in hexadecimal notation.
|
static boolean |
containsIgnoreCase(String s,
String expected)
Tests if a CharSequence ends with a specified prefix.
|
static String |
cssCamelize(String string)
Transforms the specified string from delimiter-separated (e.g.
|
static String |
cssDeCamelize(String string)
Transforms the specified string from camel-cased (e.g.
|
static <T extends CharSequence> |
defaultIfEmptyOrNull(T s,
T defaultString)
Returns either the passed in CharSequence, or if the CharSequence is
empty or
null , the default value. |
static boolean |
endsWithIgnoreCase(String s,
String expectedEnd)
Tests if a CharSequence ends with a specified prefix.
|
static boolean |
equalsChar(char expected,
CharSequence s) |
static String |
escapeXml(String text)
Escape the string to be used as xml 1.0 content be replacing the
characters '"', '&', ''', '<', and '>' into their XML entity equivalents.
|
static String |
escapeXmlAttributeValue(String attValue)
Escape the string to be used as attribute value.
|
static String |
escapeXmlChars(String s)
Escapes the characters '<', '>' and '&' into their XML entity equivalents.
|
static Color |
findColorHSL(String token)
Returns a Color parsed from the given hsl notation if found inside the given string.
|
static Color |
findColorRGB(String token)
Returns a Color parsed from the given rgb notation if found inside the given string.
|
static Color |
findColorRGBA(String token)
Returns a Color parsed from the given rgb notation.
|
static String |
formatColor(Color color)
Formats the specified color.
|
static int |
indexOf(String s,
char searchChar,
int beginIndex,
int endIndex)
Returns the index within the specified string of the first occurrence of
the specified search character.
|
static boolean |
isBlank(CharSequence s)
Tests if a CharSequence is null, empty, or contains only whitespace.
|
static boolean |
isEmptyOrNull(CharSequence s)
Returns true if the param is null or empty.
|
static boolean |
isEmptyString(CharSequence s)
Returns true if the param is not null and empty.
|
static boolean |
isNotBlank(CharSequence s)
Tests if a CharSequence is NOT null, empty, or contains only whitespace.
|
static String |
sanitizeForAppendReplacement(String toSanitize)
Sanitize a string for use in Matcher.appendReplacement.
|
static String |
sanitizeForFileName(String toSanitize)
Sanitizes a string for use as filename.
|
static String[] |
splitAtBlank(String str)
Splits the provided text into an array, using blank as the
separator.
|
static String[] |
splitAtComma(String str)
Splits the provided text into an array, using blank as the
separator.
|
static String[] |
splitAtCommaOrBlank(String str)
Splits the provided text into an array, using comma or blank as the
separator.
|
static String[] |
splitAtJavaWhitespace(String str)
Splits the provided text into an array, using whitespace as the
separator.
|
static boolean |
startsWithIgnoreCase(String s,
String expectedStart)
Tests if a CharSequence starts with a specified prefix.
|
static byte[] |
toByteArray(String content,
Charset charset)
Converts a string into a byte array using the specified encoding.
|
static String |
toRootLowerCase(String s)
Lowercases a string by checking and check for null first.
|
public static boolean isEmptyString(CharSequence s)
StringUtils.isEmpty(CharSequence)
because
this returns false if the provided string is null.s
- the string to checkpublic static boolean isEmptyOrNull(CharSequence s)
s
- the string to checkpublic static <T extends CharSequence> T defaultIfEmptyOrNull(T s, T defaultString)
null
, the default value.T
- the kind of CharSequences
- the CharSequence to checkdefaultString
- the default to return if the input is empty or nullpublic static boolean isBlank(CharSequence s)
s
- the CharSequence to checkpublic static boolean isNotBlank(CharSequence s)
s
- the CharSequence to checkpublic static boolean equalsChar(char expected, CharSequence s)
expected
- the char that we expects
- the string to checkpublic static boolean startsWithIgnoreCase(String s, String expectedStart)
s
- the string to checkexpectedStart
- the string that we expect at the beginning (has to be not null and not empty)public static boolean endsWithIgnoreCase(String s, String expectedEnd)
s
- the string to checkexpectedEnd
- the string that we expect at the end (has to be not null and not empty)public static boolean containsIgnoreCase(String s, String expected)
s
- the string to checkexpected
- the string that we expect to be a substring (has to be not null and not empty)public static String escapeXmlChars(String s)
s
- the string to escapepublic static String escapeXml(String text)
text
- the attribute valuepublic static String escapeXmlAttributeValue(String attValue)
<
, &
and "
have to be escaped (see
http://www.w3.org/TR/REC-xml/#d0e888).attValue
- the attribute valuepublic static int indexOf(String s, char searchChar, int beginIndex, int endIndex)
s
- the string to searchsearchChar
- the character to search forbeginIndex
- the index at which to start the searchendIndex
- the index at which to stop the search-1
public static Color asColorHexadecimal(String token)
token
- the token to parsepublic static Color findColorRGB(String token)
token
- the token to parsepublic static Color findColorRGBA(String token)
token
- the token to parsepublic static Color findColorHSL(String token)
token
- the token to parsepublic static String formatColor(Color color)
color
- the color to formatpublic static String sanitizeForAppendReplacement(String toSanitize)
toSanitize
- the string to sanitizepublic static String sanitizeForFileName(String toSanitize)
toSanitize
- the string to sanitizepublic static String cssCamelize(String string)
font-size
)
to camel-cased (e.g. fontSize
).string
- the string to camelizepublic static String toRootLowerCase(String s)
s
- the string to lowercasepublic static String cssDeCamelize(String string)
fontSize
)
to delimiter-separated (e.g. font-size
).
to camel-cased .string
- the string to decamelizepublic static byte[] toByteArray(String content, Charset charset)
charset
- the charsetcontent
- the string to convertpublic static String[] splitAtJavaWhitespace(String str)
Character.isWhitespace(char)
.str
- the String to parse, may be nullpublic static String[] splitAtBlank(String str)
str
- the String to parse, may be nullpublic static String[] splitAtComma(String str)
str
- the String to parse, may be nullCopyright © 2002–2025 Gargoyle Software Inc.. All rights reserved.