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 › zig › Ast › Render › renderIdentifierContents Private Function renderIdentifierContents Doc Source Private Function std.zig.Ast.Render.renderIdentifierContents
fn renderIdentifierContents (ais : *AutoIndentingStream , bytes : []const u8 ) !void Params File zig/Ast/Render.zig: 2929
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966 fn renderIdentifierContents (ais : *AutoIndentingStream , bytes : []const u8 ) !void {
var pos : usize = 0 ;
while (pos < bytes .len ) {
const byte = bytes [pos ];
switch (byte ) {
'\\' => {
const old_pos = pos ;
const res = std .zig .string_literal .parseEscapeSequence (bytes , &pos );
const escape_sequence = bytes [old_pos ..pos ];
switch (res ) {
.success => |codepoint | {
if (codepoint <= 0x7f ) {
const buf = [1 ]u8 {@as (u8 , @intCast (codepoint ))};
try ais .print ("{f}" , .{std .zig .fmtString (&buf )});
} else {
try ais .writeAll (escape_sequence );
}
},
.failure => {
// Escape the stray backslash
// This also avoids cases like "\x3\x39" becoming "\x39"
try ais .writeByte ('\\' );
try ais .writeAll (escape_sequence );
},
}
},
0x00 ...('\\' - 1 ), ('\\' + 1 )...0x7f => {
const buf = [1 ]u8 {byte };
try ais .print ("{f}" , .{std .zig .fmtString (&buf )});
pos += 1 ;
},
0x80 ...0xff => {
try ais .writeByte (byte );
pos += 1 ;
},
}
}
}