@Test public void testEscapeHTML() { assertEquals("abc", HTMLUtilities.escapeHTML("abc")); assertEquals("&#x2222;", HTMLUtilities.escapeHTML("\u2222")); assertEquals("&#x1F344;", HTMLUtilities.escapeHTML("\uD83C\uDF44")); assertEquals("&lt;abc&gt;", HTMLUtilities.escapeHTML("<abc>")); assertEquals("a&amp;b", HTMLUtilities.escapeHTML("a&b")); }
public static String escapeHTML(String text) { StringBuilder buffer = new StringBuilder(text.length()); text.codePoints().forEach(cp -> { switch (cp) { case '&': buffer.append("&amp;"); break; case '<': buffer.append("&lt;"); break; case '>': buffer.append("&gt;"); break; default: if (cp < ' ' || cp >= 0x7F) { buffer.append("&#x"); buffer.append(Integer.toString(cp, 16).toUpperCase()); buffer.append(";"); } else { buffer.appendCodePoint(cp); } break; } }); return buffer.toString(); }
HTMLUtilities { public static String escapeHTML(String text) { StringBuilder buffer = new StringBuilder(text.length()); text.codePoints().forEach(cp -> { switch (cp) { case '&': buffer.append("&amp;"); break; case '<': buffer.append("&lt;"); break; case '>': buffer.append("&gt;"); break; default: if (cp < ' ' || cp >= 0x7F) { buffer.append("&#x"); buffer.append(Integer.toString(cp, 16).toUpperCase()); buffer.append(";"); } else { buffer.appendCodePoint(cp); } break; } }); return buffer.toString(); } }
HTMLUtilities { public static String escapeHTML(String text) { StringBuilder buffer = new StringBuilder(text.length()); text.codePoints().forEach(cp -> { switch (cp) { case '&': buffer.append("&amp;"); break; case '<': buffer.append("&lt;"); break; case '>': buffer.append("&gt;"); break; default: if (cp < ' ' || cp >= 0x7F) { buffer.append("&#x"); buffer.append(Integer.toString(cp, 16).toUpperCase()); buffer.append(";"); } else { buffer.appendCodePoint(cp); } break; } }); return buffer.toString(); }  }
HTMLUtilities { public static String escapeHTML(String text) { StringBuilder buffer = new StringBuilder(text.length()); text.codePoints().forEach(cp -> { switch (cp) { case '&': buffer.append("&amp;"); break; case '<': buffer.append("&lt;"); break; case '>': buffer.append("&gt;"); break; default: if (cp < ' ' || cp >= 0x7F) { buffer.append("&#x"); buffer.append(Integer.toString(cp, 16).toUpperCase()); buffer.append(";"); } else { buffer.appendCodePoint(cp); } break; } }); return buffer.toString(); }  static String wrapAsHTML(String text); static String colorString(Color color, String text); static String colorString(String rgbColor, String text); static String colorString(String rgbColor, int value); static String spaces(int num); static String bold(String text); static String underline(String text); static String italic(String text); static boolean isHTML(String text); static String setFontSize(String text, int ptSize); static String setFont(String text, Color color, int ptSize); static String wrapWithLinkPlaceholder(String htmlText, String content); static String convertLinkPlaceholdersToHyperlinks(String text); static String toHTML(String text); static String toWrappedHTML(String text); static String toWrappedHTML(String text, int maxLineLength); static String toLiteralHTMLForTooltip(String text); static String friendlyEncodeHTML(String text); static String escapeHTML(String text); static String toLiteralHTML(String text, int maxLineLength); static String lineWrapWithHTMLLineBreaks(String text); static String lineWrapWithHTMLLineBreaks(String text, int maxLineLength); static String fromHTML(String text); static String toRGBString(Color color); static String toHexString(Color color); }
HTMLUtilities { public static String escapeHTML(String text) { StringBuilder buffer = new StringBuilder(text.length()); text.codePoints().forEach(cp -> { switch (cp) { case '&': buffer.append("&amp;"); break; case '<': buffer.append("&lt;"); break; case '>': buffer.append("&gt;"); break; default: if (cp < ' ' || cp >= 0x7F) { buffer.append("&#x"); buffer.append(Integer.toString(cp, 16).toUpperCase()); buffer.append(";"); } else { buffer.appendCodePoint(cp); } break; } }); return buffer.toString(); }  static String wrapAsHTML(String text); static String colorString(Color color, String text); static String colorString(String rgbColor, String text); static String colorString(String rgbColor, int value); static String spaces(int num); static String bold(String text); static String underline(String text); static String italic(String text); static boolean isHTML(String text); static String setFontSize(String text, int ptSize); static String setFont(String text, Color color, int ptSize); static String wrapWithLinkPlaceholder(String htmlText, String content); static String convertLinkPlaceholdersToHyperlinks(String text); static String toHTML(String text); static String toWrappedHTML(String text); static String toWrappedHTML(String text, int maxLineLength); static String toLiteralHTMLForTooltip(String text); static String friendlyEncodeHTML(String text); static String escapeHTML(String text); static String toLiteralHTML(String text, int maxLineLength); static String lineWrapWithHTMLLineBreaks(String text); static String lineWrapWithHTMLLineBreaks(String text, int maxLineLength); static String fromHTML(String text); static String toRGBString(Color color); static String toHexString(Color color); static final String HTML; static final String HTML_CLOSE; static final String BR; static final String PRE; static final String PRE_CLOSE; static final String LINK_PLACEHOLDER_OPEN; static final String LINK_PLACEHOLDER_CLOSE; static String HTML_SPACE; static String HTML_NEW_LINE; static final String MAROON; static final String GREEN; static final String BLUE; static final String PURPLE; static final String DARK_CYAN; static final String OLIVE; static final String ORANGE; static final String PINK; static final String YELLOW; static final String GRAY; }