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.

cellCount

errors.cellCount
fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usize, end_index: usize) usize

File

Code

fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usize, end_index: usize) usize {
    // Note: This is an imperfect solution. A proper implementation here would
    //       involve full grapheme cluster awareness + grapheme width data, but oh well.
    var codepoint_count: usize = 0;
    var index: usize = start_index;
    while (index < end_index) {
        const codepoint = code_page.codepointAt(index, source) orelse break;
        defer index += codepoint.byte_len;
        _ = codepointForDisplay(codepoint) orelse continue;
        codepoint_count += 1;
        // no need to count more than we will display
        if (codepoint_count >= max_source_line_codepoints + truncated_str.len) break;
    }
    return codepoint_count;
}