Class StringUtils
java.lang.Object
org.htmlunit.util.StringUtils
String utilities class for utility functions not covered by third party libraries.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ColorasColorHexadecimal(String token) Returns a Color parsed from the given RGB in hexadecimal notation.static StringcssCamelize(String string) Transforms the specified string from delimiter-separated (e.g.static StringcssDeCamelize(String string) Transforms the specified string from camel-cased (e.g.static StringescapeXmlAttributeValue(String attValue) Escape the string to be used as attribute value.static StringEscapes the characters '<', '>' and '&' into their XML entity equivalents.static ColorfindColorHSL(String token) Returns a Color parsed from the given hsl notation if found inside the given string.static ColorfindColorRGB(String token) Returns a Color parsed from the given rgb notation if found inside the given string.static ColorfindColorRGBA(String token) Returns a Color parsed from the given rgb notation.static StringformatColor(Color color) Formats the specified color.private static ColorhslToRgb(float h, float s, float l) Converts an HSL color value to RGB.private static floathueToRgb(float p, float q, float t) static intReturns the index within the specified string of the first occurrence of the specified search character.static StringsanitizeForAppendReplacement(String toSanitize) Sanitize a string for use in Matcher.appendReplacement.static StringsanitizeForFileName(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[]Splits the provided text into an array, using comma or blank as the separator.static String[]Splits the provided text into an array, using whitespace as the separator.private static intto255(float value) static byte[]toByteArray(String content, Charset charset) Converts a string into a byte array using the specified encoding.static StringLowercases a string by checking and check for null first.
-
Field Details
-
HEX_COLOR
-
RGB_COLOR
-
RGBA_COLOR
-
HSL_COLOR
-
ILLEGAL_FILE_NAME_CHARS
-
CamelizeCache_
-
-
Constructor Details
-
StringUtils
private StringUtils()Disallow instantiation of this class.
-
-
Method Details
-
escapeXmlChars
Escapes the characters '<', '>' and '&' into their XML entity equivalents. Note that sometimes we have to use this method instead ofStringEscapeUtils.escapeXml(String)orStringEscapeUtils.escapeHtml4(String)because those methods escape some unicode characters as well.- Parameters:
s- the string to escape- Returns:
- the escaped form of the specified string
-
escapeXmlAttributeValue
Escape the string to be used as attribute value. Only<,&and"have to be escaped (see http://www.w3.org/TR/REC-xml/#d0e888).- Parameters:
attValue- the attribute value- Returns:
- the escaped value
-
indexOf
Returns the index within the specified string of the first occurrence of the specified search character.- Parameters:
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- Returns:
- the index of the first occurrence of the character in the string or
-1
-
asColorHexadecimal
-
findColorRGB
-
findColorRGBA
-
findColorHSL
-
hslToRgb
-
hueToRgb
private static float hueToRgb(float p, float q, float t) -
to255
private static int to255(float value) -
formatColor
-
sanitizeForAppendReplacement
Sanitize a string for use in Matcher.appendReplacement. Replaces all \ with \\ and $ as \$ because they are used as control characters in appendReplacement.- Parameters:
toSanitize- the string to sanitize- Returns:
- sanitized version of the given string
-
sanitizeForFileName
-
cssCamelize
-
toRootLowerCase
-
cssDeCamelize
-
toByteArray
Converts a string into a byte array using the specified encoding.- Parameters:
content- the string to convertcharset- the charset- Returns:
- the String as a byte[]; if the specified encoding is not supported an empty byte[] will be returned
-
splitAtJavaWhitespace
Splits the provided text into an array, using whitespace as the separator. Whitespace is defined byCharacter.isWhitespace(char).- Parameters:
str- the String to parse, may be null- Returns:
- an array of parsed Strings, an empty array if null String input
-
splitAtBlank
-
splitAtComma
-
splitAtCommaOrBlank
-