dejavu_engine/escaper/
mod.rs1use core::{
2 fmt::{Display, Formatter, Result, Write},
3 str,
4};
5
6pub mod utils;
7
8pub trait Escaper {
9 fn write_escaped<W>(&self, fmt: W, string: &str) -> Result
10 where
11 W: Write;
12}
13
14pub struct XmlEscaper;
15
16impl Escaper for XmlEscaper {
17 fn write_escaped<W>(&self, mut fmt: W, string: &str) -> Result
18 where
19 W: Write,
20 {
21 for c in string.chars() {
22 match c {
23 '<' => fmt.write_str("<")?,
24 '>' => fmt.write_str(">")?,
25 '&' => fmt.write_str("&")?,
26 '"' => fmt.write_str(""")?,
27 '\'' => fmt.write_str("'")?,
28 _ => fmt.write_char(c)?,
29 }
30 }
31 Ok(())
32 }
33}
34
35pub struct PlainText;
36
37impl Escaper for PlainText {
38 fn write_escaped<W>(&self, mut fmt: W, string: &str) -> Result
39 where
40 W: Write,
41 {
42 fmt.write_str(string)
43 }
44}