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("<"),
14 '>' => output.push_str(">"),
15 '"' => output.push_str("""),
16 '&' => output.push_str("&"),
17 '\'' => output.push_str("'"),
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}