Java HTML Decode toHtmlString(String src, boolean noSingleQuotes)

Here you can find the source of toHtmlString(String src, boolean noSingleQuotes)

Description

to Html String

License

LGPL

Declaration

public static String toHtmlString(String src, boolean noSingleQuotes) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

public class Main {
    public static String toHtmlString(String src, boolean noSingleQuotes) {
        StringCharacterIterator iter = new StringCharacterIterator(src);
        StringBuffer buf = new StringBuffer();
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            switch (c) {
            case '\'':
                if (noSingleQuotes) {
                    buf.append(c);/*ww w.  j av a  2s  .  c  o  m*/
                } else {
                    //buf.append("'");
                    buf.append("'");
                }
                break;
            case '\"':
                buf.append(""");
                break;
            case '<':
                buf.append("&lt;");
                break;
            case '>':
                buf.append("&gt;");
                break;
            case '&':
                buf.append("&amp;");
                break;
            default:
                buf.append(c);
            }
        }
        return buf.toString();
    }
}

Related

  1. htmlDecode(String s)
  2. htmlDecode(String strSrc)
  3. htmlDecoder(String content)
  4. htmlEntityDecode(String s)
  5. htmlEntityDecodeSingle(String s)