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.

find

PkgConfig.find
pub fn find(pc: *const PkgConfig, lib_name: []const u8) ?usize

File

lib/std/zig/PkgConfig.zig:52

Code

pub fn find(pc: *const PkgConfig, lib_name: []const u8) ?usize {
    const all = pc.all;

    // Exact match means instant winner.
    for (all, 0..) |pkg, i| {
        if (mem.eql(u8, pkg.name, lib_name))
            return i;
    }

    // Next we'll try ignoring case.
    for (all, 0..) |pkg, i| {
        if (std.ascii.eqlIgnoreCase(pkg.name, lib_name))
            return i;
    }

    // Prefixed "lib" or suffixed ".0".
    for (all, 0..) |pkg, i| {
        if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
            const prefix = pkg.name[0..pos];
            const suffix = pkg.name[pos + lib_name.len ..];
            if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;
            if (suffix.len > 0 and !mem.eql(u8, suffix, ".0")) continue;
            return i;
        }
    }

    // Trimming "-1.0".
    if (mem.cutSuffix(u8, lib_name, "-1.0")) |trimmed| {
        for (all, 0..) |pkg, i| {
            if (std.ascii.eqlIgnoreCase(pkg.name, trimmed)) {
                return i;
            }
        }
    }

    return null;
}