3 //! This module contains one unit struct, which can be used to HTML-escape a
4 //! string of text (for use in a format string).
8 /// Wrapper struct which will emit the HTML-escaped version of the contained
9 /// string when passed to a format string.
10 pub(crate) struct Escape<'a>(pub &'a str);
12 impl<'a> fmt::Display for Escape<'a> {
13 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
14 // Because the internet is always right, turns out there's not that many
15 // characters to escape: http://stackoverflow.com/questions/7381974
16 let Escape(s) = *self;
19 for (i, ch) in s.char_indices() {
28 fmt.write_str(&pile_o_bits[last..i])?;
30 // NOTE: we only expect single byte characters here - which is fine as long as we
31 // only match single byte characters
36 fmt.write_str(&pile_o_bits[last..])?;