Skip to main content

json_quote_units

Function json_quote_units 

Source
pub fn json_quote_units(units: &[u16]) -> String
Expand description

What: Quote code units as JSON.stringify quotes a string. char::decode_utf16 pairs surrogates and yields an error for each unpaired one. Why: Messages and the version edit compare against the incumbent’s quoting: ", \ and the short control escapes are escaped, other units below U+0020 and unpaired surrogates become lower-case \u escapes, and everything else stays literal.

In TS you’d write (pseudocode):

const quoted = JSON.stringify(text);