escapeToSink
private fn
void 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')))) @safeEscape 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
s | Input UTF-8 string to escape. |
sink | Output sink to write escaped content to. |
quote | Quote character that must be escaped (`'"'` or `'\''`). |
asciiOnly | When true, escape non-ASCII code points using \uXXXX sequences. |