Package com.iizix.text
Class HTMLUtilities
java.lang.Object
com.iizix.text.HTMLUtilities
Utility routines for HTML text.
- Author:
- Christopher Mindus
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionstatic String
escapeCharsCodes
(String string) Escapes all characters in the string that are below 32 (space) or above or equal to 127 to a "&#nnn;".static String
escapeString
(String string, boolean doLineBreaks) Escapes a HTML format string as the rules for quoted value for HTML.static String
escapeTagValueString
(String string) Escapes a string as the rules for quoted value in HTML tag specifies.static String
replaceCharacterEntities
(String string) Replaces all strings such as © � &x0000; to character values.
Constructor Details
HTMLUtilities
public HTMLUtilities()
Method Details
escapeString
Escapes a HTML format string as the rules for quoted value for HTML.The following rules apply:
- Single CR, Single LF, CR/LF or LF/CR is replaced with '<br>' depending on the
doLineBreaks = true
. - White space characters (Tab, VT, FF) are left as is.
- '&' is replaced by '&'
- '<' is replaced with '<'
- '>' is replaced with '>'
- " is replaced by "
- All control characters (below space/0x20/32) are replaced by &#nnn;
- Parameters:
string
- The input string.doLineBreaks
- Flag indicating line breaks should be replaced with '<br>' (valid for CR+LF, a single LF or a single CR).- Returns:
- The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
- Single CR, Single LF, CR/LF or LF/CR is replaced with '<br>' depending on the
escapeTagValueString
Escapes a string as the rules for quoted value in HTML tag specifies.- White space characters (Tab, VT, FF, etc., see
Character.isWhitespace(char)
) are left as is. - '&' is replaced by '&'
- '<' and '>' are replaced with '<' and '>'
- " is replaced by "
- All control characters (below space/0x20/32) are replaced by &#nnn;, & to &, double-quote to ", < to < and > to >.
- Parameters:
string
- The input string.- Returns:
- The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
- White space characters (Tab, VT, FF, etc., see
escapeCharsCodes
Escapes all characters in the string that are below 32 (space) or above or equal to 127 to a "&#nnn;".- Parameters:
string
- The input string.- Returns:
- The escaped string.
replaceCharacterEntities
Replaces all strings such as © � &x0000; to character values.- Parameters:
string
- Input string.- Returns:
- The "encoded" string (kind of inverted encode function).