fn escape_html(input: &str, attr: bool) -> String {
let mut out = String::with_capacity(input.len());
for ch in input.chars() {
match ch {
'&' => out.push_str("&"),
'<' => out.push_str("<"),
'>' => out.push_str(">"),
'"' if attr => out.push_str("""),
'\'' if attr => out.push_str("'"),
other => out.push(other),
}
}
out
}
pub(super) fn escape_text(input: &str) -> String {
escape_html(input, false)
}
pub(super) fn escape_attr(input: &str) -> String {
escape_html(input, true)
}