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.
pubconstForcedOrdinal = struct {
pubfnfromBytes(bytes: SourceBytes) u16 {
vari: usize = 0;
varresult: u21 = 0;
while (bytes.code_page.codepointAt(i, bytes.slice)) |codepoint| : (i += codepoint.byte_len) {
constc = switch (codepoint.value) {
// Codepoints that would need a surrogate pair in UTF-16 are
// broken up into their UTF-16 code units and each code unit
// is interpreted as a digit.
0x10000...0x10FFFF => {
consthigh = @as(u16, @intCast((codepoint.value - 0x10000) >> 10)) + 0xD800;
if (result != 0) result *%= 10;
result +%= high -% '0';
constlow = @as(u16, @intCast(codepoint.value & 0x3FF)) + 0xDC00;
if (result != 0) result *%= 10;
result +%= low -% '0';
continue;
},
Codepoint.invalid => 0xFFFD,
else => codepoint.value,
};
if (result != 0) result *%= 10;
result +%= c -% '0';
}
return@truncate(result);
}
pubfnfromUtf16Le(utf16: [:0]constu16) u16 {
varresult: u16 = 0;
for (utf16) |code_unit| {
if (result != 0) result *%= 10;
result +%= std.mem.littleToNative(u16, code_unit) -% '0';
}
returnresult;
}
}