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.
pubconstCodePageLookup = struct {
lookup: std.ArrayList(SupportedCodePage) = .empty,
allocator: Allocator,
default_code_page: SupportedCodePage,
pubfninit(allocator: Allocator, default_code_page: SupportedCodePage) CodePageLookup {
return .{
.allocator = allocator,
.default_code_page = default_code_page,
};
}
pubfndeinit(self: *CodePageLookup) void {
self.lookup.deinit(self.allocator);
}
/// line_num is 1-indexedpubfnsetForLineNum(self: *CodePageLookup, line_num: usize, code_page: SupportedCodePage) !void {
constindex = line_num - 1;
if (index >= self.lookup.items.len) {
constnew_size = line_num;
constmissing_lines_start_index = self.lookup.items.len;
tryself.lookup.resize(self.allocator, new_size);
// If there are any gaps created, we need to fill them in with the value of the
// last line before the gap. This can happen for e.g. string literals that
// span multiple lines, or if the start of a file has multiple empty lines.
constfill_value = if (missing_lines_start_index > 0)
self.lookup.items[missing_lines_start_index - 1]
elseself.default_code_page;
vari: usize = missing_lines_start_index;
while (i < new_size - 1) : (i += 1) {
self.lookup.items[i] = fill_value;
}
}
self.lookup.items[index] = code_page;
}
pubfnsetForToken(self: *CodePageLookup, token: Token, code_page: SupportedCodePage) !void {
returnself.setForLineNum(token.line_number, code_page);
}
/// line_num is 1-indexedpubfngetForLineNum(self: CodePageLookup, line_num: usize) SupportedCodePage {
returnself.lookup.items[line_num - 1];
}
pubfngetForToken(self: CodePageLookup, token: Token) SupportedCodePage {
returnself.getForLineNum(token.line_number);
}
}