escapeToSink

private fnvoid escapeToSink(Sink)(scope const(char)[] s, ref Sink sink, const char quote, const bool asciiOnly) if (is(typeof(sink.put("test"))) || is(typeof(sink.put('c')))) @safe

Escape the contents of a UTF-8 string and write to a sink.

This is the core escape logic shared by escapeJSONString and writeJSONString. It handles control characters, quote escaping, and optional ASCII-only output with proper UTF-16 surrogate pair encoding for non-BMP characters.

Malformed UTF-8 sequences are replaced with the Unicode replacement character (U+FFFD).

Parameters

sInput UTF-8 string to escape.
sinkOutput sink to write escaped content to.
quoteQuote character that must be escaped (`'"'` or `'\''`).
asciiOnlyWhen true, escape non-ASCII code points using \uXXXX sequences.