Package org.htmlunit.util
Class StringUtils
- java.lang.Object
-
- org.htmlunit.util.StringUtils
-
public final class StringUtils extends java.lang.ObjectString utilities class for utility functions not covered by third party libraries.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.htmlunit.html.impl.ColorasColorHexadecimal(java.lang.String token)Returns a Color parsed from the given RGB in hexadecimal notation.static java.lang.StringcssCamelize(java.lang.String string)Transforms the specified string from delimiter-separated (e.g.static java.lang.StringcssDeCamelize(java.lang.String string)Transforms the specified string from camel-cased (e.g.static java.lang.StringescapeXmlAttributeValue(java.lang.String attValue)Escape the string to be used as attribute value.static java.lang.StringescapeXmlChars(java.lang.String s)Escapes the characters '<', '>' and '&' into their XML entity equivalents.static org.htmlunit.html.impl.ColorfindColorHSL(java.lang.String token)Returns a Color parsed from the given hsl notation if found inside the given string.static org.htmlunit.html.impl.ColorfindColorRGB(java.lang.String token)Returns a Color parsed from the given rgb notation if found inside the given string.static org.htmlunit.html.impl.ColorfindColorRGBA(java.lang.String token)Returns a Color parsed from the given rgb notation.static java.lang.StringformatColor(org.htmlunit.html.impl.Color color)Formats the specified color.static intindexOf(java.lang.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 java.util.DateparseHttpDate(java.lang.String s)Parses the specified date string, assuming that it is formatted according to RFC 1123, RFC 1036 or as an ANSI C HTTP date header.static java.lang.StringsanitizeForAppendReplacement(java.lang.String toSanitize)Sanitize a string for use in Matcher.appendReplacement.static java.lang.StringsanitizeForFileName(java.lang.String toSanitize)Sanitizes a string for use as filename.static byte[]toByteArray(java.lang.String content, java.nio.charset.Charset charset)Converts a string into a byte array using the specified encoding.static java.lang.StringtoRootLowerCaseWithCache(java.lang.String string)
-
-
-
Method Detail
-
escapeXmlChars
public static java.lang.String escapeXmlChars(java.lang.String s)
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
public static java.lang.String escapeXmlAttributeValue(java.lang.String attValue)
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
public static int indexOf(java.lang.String s, char searchChar, int beginIndex, int endIndex)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
-
parseHttpDate
public static java.util.Date parseHttpDate(java.lang.String s)
Parses the specified date string, assuming that it is formatted according to RFC 1123, RFC 1036 or as an ANSI C HTTP date header. This method returnsnullif the specified string isnullor unparseable.- Parameters:
s- the string to parse as a date- Returns:
- the date version of the specified string, or
null
-
asColorHexadecimal
public static org.htmlunit.html.impl.Color asColorHexadecimal(java.lang.String token)
Returns a Color parsed from the given RGB in hexadecimal notation.- Parameters:
token- the token to parse- Returns:
- a Color whether the token is a color RGB in hexadecimal notation; otherwise null
-
findColorRGB
public static org.htmlunit.html.impl.Color findColorRGB(java.lang.String token)
Returns a Color parsed from the given rgb notation if found inside the given string.- Parameters:
token- the token to parse- Returns:
- a Color whether the token contains a color in RGB notation; otherwise null
-
findColorRGBA
public static org.htmlunit.html.impl.Color findColorRGBA(java.lang.String token)
Returns a Color parsed from the given rgb notation.- Parameters:
token- the token to parse- Returns:
- a Color whether the token is a color in RGB notation; otherwise null
-
findColorHSL
public static org.htmlunit.html.impl.Color findColorHSL(java.lang.String token)
Returns a Color parsed from the given hsl notation if found inside the given string.- Parameters:
token- the token to parse- Returns:
- a Color whether the token contains a color in RGB notation; otherwise null
-
formatColor
public static java.lang.String formatColor(org.htmlunit.html.impl.Color color)
Formats the specified color.- Parameters:
color- the color to format- Returns:
- the specified color, formatted
-
sanitizeForAppendReplacement
public static java.lang.String sanitizeForAppendReplacement(java.lang.String toSanitize)
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
public static java.lang.String sanitizeForFileName(java.lang.String toSanitize)
Sanitizes a string for use as filename. Replaces \, /, |, :, ?, *, ", <, >, control chars by _ (underscore).- Parameters:
toSanitize- the string to sanitize- Returns:
- sanitized version of the given string
-
cssCamelize
public static java.lang.String cssCamelize(java.lang.String string)
Transforms the specified string from delimiter-separated (e.g.font-size) to camel-cased (e.g.fontSize).- Parameters:
string- the string to camelize- Returns:
- the transformed string
-
toRootLowerCaseWithCache
public static java.lang.String toRootLowerCaseWithCache(java.lang.String string)
-
cssDeCamelize
public static java.lang.String cssDeCamelize(java.lang.String string)
Transforms the specified string from camel-cased (e.g.fontSize) to delimiter-separated (e.g.font-size). to camel-cased .- Parameters:
string- the string to decamelize- Returns:
- the transformed string
-
toByteArray
public static byte[] toByteArray(java.lang.String content, java.nio.charset.Charset charset)Converts a string into a byte array using the specified encoding.- Parameters:
charset- the charsetcontent- the string to convert- Returns:
- the String as a byte[]; if the specified encoding is not supported an empty byte[] will be returned
-
-