crabmail

Static HTML email archive viewer in Rust
git clone git://git.alexwennerberg.com/crabmail
Log | Files | Refs | README | LICENSE

util.rs (752B) - raw


      1 // less efficient, easier api
      2 pub fn xml_safe(text: &str) -> String {
      3     // note we escape more than we need to
      4     let mut dest = Vec::new();
      5     xml_escape(text, &mut dest);
      6     std::str::from_utf8(&dest).unwrap().to_owned()
      7 }
      8 
      9 pub fn xml_escape(text: &str, dest: &mut Vec<u8>) {
     10     for c in text.bytes() {
     11         match c {
     12             b'&' => dest.extend_from_slice(b"&amp;"),
     13             b'<' => dest.extend_from_slice(b"&lt;"),
     14             b'>' => dest.extend_from_slice(b"&gt;"),
     15             b'"' => dest.extend_from_slice(b"&quot;"),
     16             b'\'' => dest.extend_from_slice(b"&#39;"),
     17             // Quick and dirty email obfuscation
     18             b'@' => dest.extend_from_slice(b"&#x40;"),
     19             _ => dest.push(c),
     20         }
     21     }
     22 }