Skip to main content

nova_rt_json_quote

Function nova_rt_json_quote 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nova_rt_json_quote( s: *const NovaStr, ) -> *mut NovaStr
Expand description

s as a JSON string literal, quotation marks included: the body of std/json’s quote.

" and \ take a backslash. The five control characters with a short escape become \n, \r, \t, \b and \f, and every other byte below 0x20 becomes \u00XX in lowercase hex (RFC 8259). Everything else is copied as it is. Working on bytes is exact: every byte of a multi-byte UTF-8 character is 0x80 or above, so none can be mistaken for one of these, and every slice copied ends next to an ASCII byte, on a character boundary. The Nova-level quote this replaces built a [Char] and scanned it character by character.

The escaped length is counted first, so the result is written once, straight into its GC buffer.

GC safety: s’s bytes are read after the result’s buffer is allocated, kept alive across it as [gc_str_filled] describes.

§Safety

s must be a valid NovaStr pointer.