com.gargoylesoftware.htmlunit.util
Class StringUtils

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.util.StringUtils

public final class StringUtils
extends Object

String utilities class for utility functions not covered by third party libraries.

Version:
$Revision: 8491 $
Author:
Daniel Gredler, Ahmed Ashour, Martin Tamme, Ronald Brill

Method Summary
static Color asColorHexadecimal(String token)
          Returns a Color parsed from the given RGB in hexadecimal notation.
static Color asColorRGB(String token)
          Returns a Color parsed from the given rgb notation.
static boolean containsWhitespace(String s)
          Returns true if the specified string contains whitespace, false otherwise.
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 findColorRGB(String token)
          Returns a Color parsed from the given rgb notation.
static String formatColor(Color aColor)
          Formats the specified color.
static String formatHttpDate(Date date)
          Formats the specified date according to RFC 1123.
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 isColorRGB(String token)
          Returns true if the specified token is in RGB notation.
static Date parseHttpDate(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 String sanitizeForAppendReplacement(String toSanitize)
          Sanitize a string for use in Matcher.appendReplacement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

escapeXmlChars

public static String escapeXmlChars(String s)
Escapes the characters '<', '>' and '&' into their XML entity equivalents. Note that sometimes we have to use this method instead of StringEscapeUtils.escapeXml(String) or StringEscapeUtils.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 String escapeXmlAttributeValue(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

containsWhitespace

public static boolean containsWhitespace(String s)
Returns true if the specified string contains whitespace, false otherwise.

Parameters:
s - the string to check for whitespace
Returns:
true if the specified string contains whitespace, false otherwise

indexOf

public 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.

Parameters:
s - the string to search
searchChar - the character to search for
beginIndex - the index at which to start the search
endIndex - 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 Date parseHttpDate(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 returns null if the specified string is null or unparseable.

Parameters:
s - the string to parse as a date
Returns:
the date version of the specified string, or null

asColorHexadecimal

public static Color asColorHexadecimal(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

isColorRGB

public static boolean isColorRGB(String token)
Returns true if the specified token is in RGB notation.

Parameters:
token - the token to check
Returns:
whether the token is a color in RGB notation or not

asColorRGB

public static Color asColorRGB(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

findColorRGB

public static Color findColorRGB(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

formatColor

public static String formatColor(Color aColor)
Formats the specified color.

Parameters:
aColor - the color to format
Returns:
the specified color, formatted

formatHttpDate

public static String formatHttpDate(Date date)
Formats the specified date according to RFC 1123.

Parameters:
date - the date to format
Returns:
the specified date, formatted according to RFC 1123

sanitizeForAppendReplacement

public static String sanitizeForAppendReplacement(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


Copyright © 2002–2013 Gargoyle Software Inc.. All rights reserved.