]>
git.proxmox.com Git - rustc.git/blob - src/librustdoc/html/escape.rs
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 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
.bytes().enumerate() {
21 '
<'
| '
>'
| '
&'
| '
\''
| '
"' => {
22 fmt.write_str(&pile_o_bits[last.. i])?;
23 let s = match ch as char {
39 fmt
.write_str(&pile_o_bits
[last
..])?
;