use alloc::string::String;
use core::fmt::Write as _;
use crate::Render;
#[inline]
pub fn escape_into(input: &str, buf: &mut String) {
for c in input.chars() {
match c {
'&' => buf.push_str("&"),
'<' => buf.push_str("<"),
'>' => buf.push_str(">"),
'"' => buf.push_str("""),
_ => buf.push(c),
};
}
}
pub struct PreEscaped<T: ?Sized>(pub T);
impl Render for PreEscaped<&str> {
#[inline]
fn render_to(self, buf: &mut String) {
buf.push_str(self.0);
}
}
impl Render for PreEscaped<String> {
#[inline]
fn render_to(self, buf: &mut String) {
buf.push_str(&self.0);
}
}
impl Render for PreEscaped<core::fmt::Arguments<'_>> {
#[inline]
fn render_to(self, buf: &mut String) {
let _ = buf.write_fmt(self.0);
}
}