Quote and escape `value` using only the escape sequences that `parser::split_line` recognises (`\\`, `\"`, `\n`, `\t`, `\r`, `\0`). Avoids `format!("{:?}", …)` because Rust's Debug impl also emits `\u{N}` for non-printable Unicode, which the parser does not understand and would silently corrupt on the next read.
(value: &str)
| 159 | /// for non-printable Unicode, which the parser does not understand and would |
| 160 | /// silently corrupt on the next read. |
| 161 | fn escape_for_parser(value: &str) -> String { |
| 162 | let mut out = String::with_capacity(value.len() + 2); |
| 163 | out.push('"'); |
| 164 | for c in value.chars() { |
| 165 | match c { |
| 166 | '\\' => out.push_str("\\\\"), |
| 167 | '"' => out.push_str("\\\""), |
| 168 | '\n' => out.push_str("\\n"), |
| 169 | '\t' => out.push_str("\\t"), |
| 170 | '\r' => out.push_str("\\r"), |
| 171 | '\0' => out.push_str("\\0"), |
| 172 | c => out.push(c), |
| 173 | } |
| 174 | } |
| 175 | out.push('"'); |
| 176 | out |
| 177 | } |
| 178 | |
| 179 | fn rewrite_result( |
| 180 | state: &mut State, |
no test coverage detected