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.

tryParseDigits

Parse digits until a non-digit character is found.

parse.tryParseDigits
fn tryParseDigits(comptime T: type, stream: *FloatStream, x: *T, comptime base: u8) void

File

Code

fn tryParseDigits(comptime T: type, stream: *FloatStream, x: *T, comptime base: u8) void {
    // Try to parse 8 digits at a time, using an optimized algorithm.
    // This only supports decimal digits.
    if (base == 10) {
        while (stream.hasLen(8)) {
            const v = stream.readU64Unchecked();
            if (!isEightDigits(v)) {
                break;
            }

            x.* = x.* *% 1_0000_0000 +% parse8Digits(v);
            stream.advance(8);
        }
    }

    while (stream.scanDigit(base)) |digit| {
        x.* *%= base;
        x.* +%= digit;
    }
}