public static String escapeHTML()

in doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java [224:272]


    public static String escapeHTML(final String text, final boolean xmlMode) {
        if (text == null) {
            return "";
        }

        int length = text.length();
        StringBuilder buffer = new StringBuilder(length);

        for (int i = 0; i < length; ++i) {
            char c = text.charAt(i);
            switch (c) {
                case '<':
                    buffer.append("&lt;");
                    break;
                case '>':
                    buffer.append("&gt;");
                    break;
                case '&':
                    buffer.append("&amp;");
                    break;
                case '\"':
                    buffer.append("&quot;");
                    break;
                default:
                    if (xmlMode) {
                        if (c == '\'') {
                            buffer.append("&apos;");
                        } else {
                            buffer.append(c);
                        }
                    } else {
                        if (c <= ASCII) {
                            // ASCII.
                            buffer.append(c);
                        } else {
                            buffer.append("&#x");
                            if (isHighSurrogate(c)) {
                                buffer.append(Integer.toHexString(toCodePoint(c, text.charAt(++i))));
                            } else {
                                buffer.append(Integer.toHexString(c));
                            }
                            buffer.append(';');
                        }
                    }
            }
        }

        return buffer.toString();
    }