1use alloc::string::String;
2use core::fmt::Write as _;
3
4use crate::Render;
5
6#[inline]
9pub fn escape_into(input: &str, buf: &mut String) {
10 for c in input.chars() {
11 match c {
12 '&' => buf.push_str("&"),
13 '<' => buf.push_str("<"),
14 '>' => buf.push_str(">"),
15 '"' => buf.push_str("""),
16 _ => buf.push(c),
17 };
18 }
19}
20
21pub struct PreEscaped<T: ?Sized>(pub T);
24
25impl Render for PreEscaped<&str> {
26 #[inline]
27 fn render_to(self, buf: &mut String) {
28 buf.push_str(self.0);
29 }
30}
31
32impl Render for PreEscaped<String> {
33 #[inline]
34 fn render_to(self, buf: &mut String) {
35 buf.push_str(&self.0);
36 }
37}
38
39impl Render for PreEscaped<core::fmt::Arguments<'_>> {
40 #[inline]
41 fn render_to(self, buf: &mut String) {
42 let _ = buf.write_fmt(self.0);
43 }
44}