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

Class HtmlEscapers

corpus/java/training/guava/html/HtmlEscapers.java:38–72  ·  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

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

Callers

nothing calls this directly

Calls 3

builderMethod · 0.95
buildMethod · 0.45
addEscapeMethod · 0.45

Tested by

no test coverage detected