MCPcopy Create free account
hub / github.com/antlr/codebuff / HtmlEscapers

Class HtmlEscapers

output/java_guava/1.4.17/HtmlEscapers.java:40–68  ·  view source on GitHub ↗

Escaper instances suitable for strings to be included in HTML attribute values and most elements' text contents. When possible, avoid manual escaping by using templating systems and high-level APIs that provide autoescaping. One Google-authored templating system available for extern

Source from the content-addressed store, hash-verified

38
39
40@Beta
41@GwtCompatible
42public final class HtmlEscapers {
43 /**
44 * Returns an {@link Escaper} instance that escapes HTML metacharacters as specified by
45 * <a href="http://www.w3.org/TR/html4/">HTML 4.01</a>. The resulting strings can be used both in
46 * attribute values and in <em>most</em> elements' text contents, provided that the HTML
47 * document's character encoding can encode any non-ASCII code points in the input (as UTF-8 and
48 * other Unicode encodings can).
49 *
50 *
51 * <p><b>Note:</b> This escaper only performs minimal escaping to make content structurally
52 * compatible with HTML. Specifically, it does not perform entity replacement (symbolic or
53 * numeric), so it does not replace non-ASCII code points with character references. This escaper
54 * escapes only the following five ASCII characters: {@code '"&<>}.
55 */
56
57 public static Escaper htmlEscaper() {
58 return HTML_ESCAPER;
59 }
60
61 // For each xxxEscaper() method, please add links to external reference pages
62 // that are considered authoritative for the behavior of that escaper.
63
64 private static final Escaper HTML_ESCAPER = Escapers.builder().addEscape('"', "&quot;")
65 // Note: "&apos;" is not defined in HTML 4.01.
66.addEscape('\'', "&#39;").addEscape('&', "&amp;").addEscape('<', "&lt;").addEscape('>', "&gt;").build();
67 private HtmlEscapers() {}
68}

Callers

nothing calls this directly

Calls 3

builderMethod · 0.95
buildMethod · 0.45
addEscapeMethod · 0.45

Tested by

no test coverage detected