@Test public void testEscapeHtml() { assertEquals("nothing to escape", Escaping.escapeHtml("nothing to escape")); assertEquals("&amp;", Escaping.escapeHtml("&")); assertEquals("&lt;", Escaping.escapeHtml("<")); assertEquals("&gt;", Escaping.escapeHtml(">")); assertEquals("&quot;", Escaping.escapeHtml("\"")); assertEquals("&lt; start", Escaping.escapeHtml("< start")); assertEquals("end &gt;", Escaping.escapeHtml("end >")); assertEquals("&lt; both &gt;", Escaping.escapeHtml("< both >")); assertEquals("&lt; middle &amp; too &gt;", Escaping.escapeHtml("< middle & too >")); }
public static String escapeHtml(String input) { StringBuilder sb = null; loop: for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); String replacement; switch (c) { case '&': replacement = "&amp;"; break; case '<': replacement = "&lt;"; break; case '>': replacement = "&gt;"; break; case '\"': replacement = "&quot;"; break; default: if (sb != null) { sb.append(c); } continue loop; } if (sb == null) { sb = new StringBuilder(); sb.append(input, 0, i); } sb.append(replacement); } return sb != null ? sb.toString() : input; }
Escaping { public static String escapeHtml(String input) { StringBuilder sb = null; loop: for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); String replacement; switch (c) { case '&': replacement = "&amp;"; break; case '<': replacement = "&lt;"; break; case '>': replacement = "&gt;"; break; case '\"': replacement = "&quot;"; break; default: if (sb != null) { sb.append(c); } continue loop; } if (sb == null) { sb = new StringBuilder(); sb.append(input, 0, i); } sb.append(replacement); } return sb != null ? sb.toString() : input; } }
Escaping { public static String escapeHtml(String input) { StringBuilder sb = null; loop: for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); String replacement; switch (c) { case '&': replacement = "&amp;"; break; case '<': replacement = "&lt;"; break; case '>': replacement = "&gt;"; break; case '\"': replacement = "&quot;"; break; default: if (sb != null) { sb.append(c); } continue loop; } if (sb == null) { sb = new StringBuilder(); sb.append(input, 0, i); } sb.append(replacement); } return sb != null ? sb.toString() : input; }  }
Escaping { public static String escapeHtml(String input) { StringBuilder sb = null; loop: for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); String replacement; switch (c) { case '&': replacement = "&amp;"; break; case '<': replacement = "&lt;"; break; case '>': replacement = "&gt;"; break; case '\"': replacement = "&quot;"; break; default: if (sb != null) { sb.append(c); } continue loop; } if (sb == null) { sb = new StringBuilder(); sb.append(input, 0, i); } sb.append(replacement); } return sb != null ? sb.toString() : input; }  static String escapeHtml(String input); static String unescapeString(String s); static String percentEncodeUrl(String s); static String normalizeLabelContent(String input); }
Escaping { public static String escapeHtml(String input) { StringBuilder sb = null; loop: for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); String replacement; switch (c) { case '&': replacement = "&amp;"; break; case '<': replacement = "&lt;"; break; case '>': replacement = "&gt;"; break; case '\"': replacement = "&quot;"; break; default: if (sb != null) { sb.append(c); } continue loop; } if (sb == null) { sb = new StringBuilder(); sb.append(input, 0, i); } sb.append(replacement); } return sb != null ? sb.toString() : input; }  static String escapeHtml(String input); static String unescapeString(String s); static String percentEncodeUrl(String s); static String normalizeLabelContent(String input); static final String ESCAPABLE; static final String ENTITY; }