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 library itself.
pubconstDiagnostics = struct {
allocator: std.mem.Allocator,
/// The common root directory for all extracted files if there is one.root_dir: []constu8 = "",
saw_first_file: bool = false,
pubfndeinit(self: *Diagnostics) void {
self.allocator.free(self.root_dir);
self.* = undefined;
}
// This function assumes name is a filename from a zip file which has already been verified to
// not start with a slash, backslashes have been normalized to forward slashes, and directories
// always end in a slash.
pubfnnextFilename(self: *Diagnostics, name: []constu8) error{OutOfMemory}!void {
if (!self.saw_first_file) {
self.saw_first_file = true;
std.debug.assert(self.root_dir.len == 0);
constroot_len = std.mem.findScalar(u8, name, '/') orelsereturn;
std.debug.assert(root_len > 0);
self.root_dir = tryself.allocator.dupe(u8, name[0..root_len]);
} elseif (self.root_dir.len > 0) {
if (!filenameInRoot(name, self.root_dir)) {
self.allocator.free(self.root_dir);
self.root_dir = "";
}
}
}
}