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 library itself.

init

Parses the output of pkg-config --list-all.

PkgConfig.init
pub fn init(arena: Allocator, stdout: []const u8, diagnostic: ?*Diagnostic) InitError!PkgConfig

File

lib/std/zig/PkgConfig.zig:24

Code

pub fn init(arena: Allocator, stdout: []const u8, diagnostic: ?*Diagnostic) InitError!PkgConfig {
    var list: std.ArrayList(Pkg) = .empty;
    var line_it = mem.tokenizeAny(u8, stdout, "\r\n");
    var line_index: usize = 0;
    while (line_it.next()) |line| : (line_index += 1) {
        if (mem.trim(u8, line, " \t").len == 0) continue;
        var tok_it = mem.tokenizeAny(u8, line, " \t");
        try list.append(arena, .{
            .name = tok_it.next() orelse {
                if (diagnostic) |d| d.* = .{
                    .invalid_line_index = line_index,
                    .invalid_line = line,
                };
                return error.InvalidPkgConfigOutput;
            },
            .desc = tok_it.rest(),
        });
    }
    try list.shrinkToLen(arena);
    return .{ .all = list.toOwnedSliceAssert() };
}