MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / escape_for_parser

Function escape_for_parser

src/testdrive/src/action/sql.rs:161–177  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

159/// for non-printable Unicode, which the parser does not understand and would
160/// silently corrupt on the next read.
161fn 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
179fn rewrite_result(
180 state: &mut State,

Callers 2

rewrite_resultFunction · 0.85
fmtMethod · 0.85

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected