• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[doc(hidden)]
quote_bytes_to(bytes: &[u8], buf: &mut String)2 pub fn quote_bytes_to(bytes: &[u8], buf: &mut String) {
3     for &c in bytes {
4         match c {
5             b'\n' => buf.push_str(r"\n"),
6             b'\r' => buf.push_str(r"\r"),
7             b'\t' => buf.push_str(r"\t"),
8             b'\'' => buf.push_str("\\\'"),
9             b'"' => buf.push_str("\\\""),
10             b'\\' => buf.push_str(r"\\"),
11             b'\x20'..=b'\x7e' => buf.push(c as char),
12             _ => {
13                 buf.push('\\');
14                 buf.push((b'0' + (c >> 6)) as char);
15                 buf.push((b'0' + ((c >> 3) & 7)) as char);
16                 buf.push((b'0' + (c & 7)) as char);
17             }
18         }
19     }
20 }
21 
quote_escape_bytes_to(bytes: &[u8], buf: &mut String)22 pub(crate) fn quote_escape_bytes_to(bytes: &[u8], buf: &mut String) {
23     buf.push('"');
24     quote_bytes_to(bytes, buf);
25     buf.push('"');
26 }
27 
28 #[doc(hidden)]
quote_escape_bytes(bytes: &[u8]) -> String29 pub fn quote_escape_bytes(bytes: &[u8]) -> String {
30     let mut r = String::new();
31     quote_escape_bytes_to(bytes, &mut r);
32     r
33 }
34 
print_str_to(s: &str, buf: &mut String)35 pub(crate) fn print_str_to(s: &str, buf: &mut String) {
36     // TODO: keep printable Unicode
37     quote_escape_bytes_to(s.as_bytes(), buf);
38 }
39