Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Function

parseName

Public Function
std.coff.ArchiveMemberHeader.parseName
pub fn parseName(
        self: *const ArchiveMemberHeader,
        opt_longnames: ?[]const u8,
    ) ![]const u8

Extracts the name of the member by either reading it directly from the header, or by finding it inside the longnames member, if provided.

Params

File

coff.zig:2029
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
    pub fn parseName(
        self: *const ArchiveMemberHeader,
        opt_longnames: ?[]const u8,
    ) ![]const u8 {
        const trim = std.mem.trimEnd(u8, &self.name, &.{' '});

        if (trim.len == 0) return error.BadName;
        return if (trim[0] == '/') name: {
            if (trim.len == 1 or
                trim.len == 2 and trim[1] == '/')
                break :name trim;

            const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch
                return error.BadName;

            if (opt_longnames) |longnames| {
                if (offset >= longnames.len) return error.BadName;
                break :name std.mem.sliceTo(longnames[@intCast(offset)..], 0);
            } else return error.NoLongNames;
        } else if (trim[trim.len - 1] == '/')
            trim[0 .. trim.len - 1]
        else
            return error.BadName;
    }