Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › json › Stringify › encodeJsonStringChars Public Function encodeJsonStringChars Doc Source Public Function std.json.Stringify.encodeJsonStringChars
pub fn encodeJsonStringChars (chars : []const u8 , options : Options , writer : *Writer ) Error !void Params File json/Stringify.zig: 677
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716 pub fn encodeJsonStringChars (chars : []const u8 , options : Options , writer : *Writer ) Error !void {
var write_cursor : usize = 0 ;
var i : usize = 0 ;
if (options .escape_unicode ) {
while (i < chars .len ) : (i += 1 ) {
switch (chars [i ]) {
// normal ascii character
0x20 ...0x21 , 0x23 ...0x5B , 0x5D ...0x7E => {},
0x00 ...0x1F , '\\' , '\"' => {
// Always must escape these.
try writer .writeAll (chars [write_cursor ..i ]);
try outputSpecialEscape (chars [i ], writer );
write_cursor = i + 1 ;
},
0x7F ...0xFF => {
try writer .writeAll (chars [write_cursor ..i ]);
const ulen = std .unicode .utf8ByteSequenceLength (chars [i ]) catch unreachable ;
const codepoint = std .unicode .utf8Decode (chars [i ..][0 ..ulen ]) catch unreachable ;
try outputUnicodeEscape (codepoint , writer );
i += ulen - 1 ;
write_cursor = i + 1 ;
},
}
}
} else {
while (i < chars .len ) : (i += 1 ) {
switch (chars [i ]) {
// normal bytes
0x20 ...0x21 , 0x23 ...0x5B , 0x5D ...0xFF => {},
0x00 ...0x1F , '\\' , '\"' => {
// Always must escape these.
try writer .writeAll (chars [write_cursor ..i ]);
try outputSpecialEscape (chars [i ], writer );
write_cursor = i + 1 ;
},
}
}
}
try writer .writeAll (chars [write_cursor ..chars .len ]);
}
Write
charstowriteras JSON encoded string characters.