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 › StringEscapeWriter Public Struct StringEscapeWriter Doc Source Public Struct std.zig.StringEscapeWriter
pub const StringEscapeWriter = struct Fields Functions pub fn init (out : *Writer , buffer : []u8 ) @This () fn drain (w : *Writer , data : []const []const u8 , splat : usize ) Io .Writer .Error !usize File zig.zig: 587
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618 pub const StringEscapeWriter = struct {
out : *Writer ,
writer : Writer ,
pub fn init (out : *Writer , buffer : []u8 ) @This () {
return .{
.out = out ,
.writer = .{
.vtable = &.{ .drain = @This ().drain },
.buffer = buffer ,
},
};
}
fn drain (w : *Writer , data : []const []const u8 , splat : usize ) Io .Writer .Error !usize {
const sew : *StringEscapeWriter = @alignCast (@fieldParentPtr ("writer" , w ));
const out = sew .out ;
try stringEscape (w .buffered (), out );
w .end = 0 ;
var n : usize = 0 ;
for (data [0 .. data .len - 1 ]) |bytes | {
try stringEscape (bytes , out );
n += bytes .len ;
}
const pattern = data [data .len - 1 ];
for (0 ..splat ) |_ | {
try stringEscape (pattern , out );
n += pattern .len ;
}
return n ;
}
}