Android Utililty Methods HTML String Escape

List of utility methods to do HTML String Escape

Description

The list of methods to do HTML String Escape are organized into topic(s).

Method

StringescapeHtml(String html)
See: http://www.javapractices.com/topic/TopicAction.do?Id=96
final StringBuilder escapedHtml = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(
        html);
char character = iterator.current();
while (character != CharacterIterator.DONE) {
    if (character == '<') {
        escapedHtml.append("&lt;");
    } else if (character == '>') {
...
StringstripHTMLTags(String textToStrip)
Strip a String by removing HTML elements
StringBuffer returnText = new StringBuffer(textToStrip.length());
CharacterIterator iterator = new StringCharacterIterator(
        textToStrip);
boolean finished = true;
boolean started = false;
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator
        .next()) {
    if (ch == '<') {
...
StringcheckHtmlView(String strString)
check Html View
String strNew = "";
try {
    StringBuffer strTxt = new StringBuffer("");
    char chrBuff;
    int len = strString.length();
    for (int i = 0; i < len; i++) {
        chrBuff = (char) strString.charAt(i);
        switch (chrBuff) {
...
StringtoHTMLString(String s)
to HTML String
StringBuffer stringbuffer = new StringBuffer();
for (int i = 0; s != null && i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == '\'')
        stringbuffer.append(c);
    else if (c == '"')
        stringbuffer.append(c);
    else if (c == '\n')
...
booleanisHTML(String s)
is HTML
assert s != null : "Verify Null string";
Pattern htmlPattern1 = Pattern
        .compile("<[a-zA-Z]+[0-9]*(\\s[a-zA-Z]+[0-9]*=.*)*\\s*/??>");
Pattern htmlPattern2 = Pattern.compile("&#?[a-z0-9]+;");
Matcher m1 = htmlPattern1.matcher(s);
Matcher m2 = htmlPattern2.matcher(s);
return m1.find() || m2.find();