(value: &str)
| 113 | } |
| 114 | |
| 115 | fn render_string(value: &str) -> String { |
| 116 | let mut rendered = String::with_capacity(value.len() + 2); |
| 117 | rendered.push('"'); |
| 118 | for ch in value.chars() { |
| 119 | match ch { |
| 120 | '"' => rendered.push_str("\\\""), |
| 121 | '\\' => rendered.push_str("\\\\"), |
| 122 | '\n' => rendered.push_str("\\n"), |
| 123 | '\r' => rendered.push_str("\\r"), |
| 124 | '\t' => rendered.push_str("\\t"), |
| 125 | '\u{08}' => rendered.push_str("\\b"), |
| 126 | '\u{0C}' => rendered.push_str("\\f"), |
| 127 | control if control.is_control() => push_unicode_escape(&mut rendered, control), |
| 128 | plain => rendered.push(plain), |
| 129 | } |
| 130 | } |
| 131 | rendered.push('"'); |
| 132 | rendered |
| 133 | } |
| 134 | |
| 135 | fn push_unicode_escape(rendered: &mut String, control: char) { |
| 136 | const HEX: &[u8; 16] = b"0123456789abcdef"; |
no test coverage detected