bracket/
escape.rs

1//! Escape function trait and default functions.
2//!
3//! The default is to escape for HTML content using `escape_html`.
4
5/// Type for escape functions.
6pub type EscapeFn = Box<dyn Fn(&str) -> String + Send + Sync>;
7
8/// Escape for HTML output.
9pub fn html(s: &str) -> String {
10    let mut output = String::new();
11    for c in s.chars() {
12        match c {
13            '<' => output.push_str("&lt;"),
14            '>' => output.push_str("&gt;"),
15            '"' => output.push_str("&quot;"),
16            '&' => output.push_str("&amp;"),
17            '\'' => output.push_str("&#x27;"),
18            _ => output.push(c),
19        }
20    }
21    output
22}
23
24/// Do not escape output.
25pub fn noop(s: &str) -> String {
26    s.to_owned()
27}