pub fn write_string(out: &mut String, text: &str)Expand description
Appends text to out as a JSON string literal, quotes included.
The escaping is complete and the same every time:
"and\are escaped as\"and\\;- the control characters U+0000 to U+001F are escaped, with the short forms
\b \f \n \r \twhere JSON has one and\u00XX(lowercase hex) otherwise; - U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are escaped as
\u2028and\u2029: JSON allows them raw, but JavaScript before ES2019 ends a line at them, so raw ones break JSON embedded in a script; - everything else, including
/, DEL, and all other non-ASCII text, is copied unchanged as UTF-8.
So no string can end the literal early or put a raw line break in it,
whatever it contains: the output is always exactly one JSON string token
that decodes back to text. Unescaped stretches are copied in bulk, found
eight bytes at a time.
ยงExamples
let mut out = String::from("{\"msg\":");
jsonx_lib::write_string(&mut out, "say \"hi\"\n\u{2028}");
out.push('}');
assert_eq!(out, r#"{"msg":"say \"hi\"\n\u2028"}"#);