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.
inlinefnhandleMultilineCarriageReturn(
source: []constu8,
line_handler: *LineHandler,
index: usize,
result: *UncheckedSliceWriter,
source_mappings: ?*SourceMappings,
) !void {
// This is a dumb way to go about this, but basically we want to determine
// if this is part of a distinct CRLF or LFCR pair. This function call will detect
// LFCR pairs correctly since the function we're in will only be called on CR,
// but will not detect CRLF pairs since it only looks at the line ending before the
// CR. So, we do a second (forward) check if the first fails to detect CRLF that is
// not part of another pair.
constis_lfcr_pair = line_handler.currentIndexFormsLineEndingPair(index);
constis_crlf_pair = !is_lfcr_pairandformsLineEndingPair(source, '\r', index + 1);
// Note: Bare \r within a multiline comment should *not* be treated as a line ending for the
// purposes of removing comments, but *should* be treated as a line ending for the
// purposes of line counting/source mapping
_ = line_handler.incrementLineNumber(index);
// So only write the \r if it's part of a CRLF/LFCR pairif (is_lfcr_pairoris_crlf_pair) {
result.write('\r');
}
// And otherwise, we want to collapse the source mapping so that we can still know which
// line came from where.
else {
// Because the line gets collapsed, we need to decrement line number so that
// the next collapse acts on the first of the collapsed line numbers
line_handler.line_number -= 1;
if (source_mappings) |mappings| {
trymappings.collapse(line_handler.line_number, 1);
}
}
}