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
pubfndumpHexFallible(t: Io.Terminal, bytes: []constu8) !void {
constw = t.writer;
varchunks = mem.window(u8, bytes, 16, 16);
while (chunks.next()) |window| {
// 1. Print the address.constaddress = (@intFromPtr(bytes.ptr) + 0x10 * @divCeil(chunks.indexorelsebytes.len, 16) - 0x10);
tryt.setColor(.dim);
// We print the address in lowercase and the bytes in uppercase hexadecimal to distinguish them more.// Also, make sure all lines are aligned by padding the address.tryw.print("{x:0>[1]} ", .{ address, @sizeOf(usize) * 2 });
tryt.setColor(.reset);
// 2. Print the bytes.for (window, 0..) |byte, index| {
tryw.print("{X:0>2} ", .{byte});
if (index == 7) tryw.writeByte(' ');
}
tryw.writeByte(' ');
if (window.len < 16) {
varmissing_columns = (16 - window.len) * 3;
if (window.len < 8) missing_columns += 1;
tryw.splatByteAll(' ', missing_columns);
}
// 3. Print the characters.for (window) |byte| {
if (std.ascii.isPrint(byte)) {
tryw.writeByte(byte);
} else {
// Related: https://github.com/ziglang/zig/issues/7600if (t.mode == .windows_api) {
tryw.writeByte('.');
continue;
}
// Let's print some common control codes as graphical Unicode symbols.// We don't want to do this for all control codes because most control codes apart from// the ones that Zig has escape sequences for are likely not very useful to print as symbols.switch (byte) {
'\n' => tryw.writeAll("␊"),
'\r' => tryw.writeAll("␍"),
'\t' => tryw.writeAll("␉"),
else => tryw.writeByte('.'),
}
}
}
tryw.writeByte('\n');
}
}
Prints a hexadecimal view of the bytes, returning any error that occurs.