Zig 0.17.0-dev (Split by item)
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.
Zig › compiler/ › resinator/ › errors.zig › writeSourceSlice
writeSourceSlice
errors.writeSourceSlice
fn writeSourceSlice (buf : []u8 , slice : []const u8 , code_page : SupportedCodePage ) VisualLine
File
Code
fn writeSourceSlice (buf : []u8 , slice : []const u8 , code_page : SupportedCodePage ) VisualLine {
var src_i : usize = 0 ;
var dest_i : usize = 0 ;
var codepoint_count : usize = 0 ;
while (src_i < slice .len ) {
const codepoint = code_page .codepointAt (src_i , slice ) orelse break ;
defer src_i += codepoint .byte_len ;
const display_codepoint = codepointForDisplay (codepoint ) orelse continue ;
codepoint_count += 1 ;
if (codepoint_count > max_source_line_codepoints ) {
return .{ .line = buf [0 ..dest_i ], .truncated = true };
}
const utf8_len = std .unicode .utf8Encode (display_codepoint , buf [dest_i ..]) catch unreachable ;
dest_i += utf8_len ;
}
return .{ .line = buf [0 ..dest_i ], .truncated = false };
}