fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 buf: []const u88051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067fn parseBitCount(buf: []const u8) std.fmt.ParseIntError!u16 {
if (buf.len == 0) return error.InvalidCharacter;
var x: u16 = 0;
for (buf) |c| {
const digit = switch (c) {
'0'...'9' => c - '0',
else => return error.InvalidCharacter,
};
if (x != 0) x = try std.math.mul(u16, x, 10);
x = try std.math.add(u16, x, digit);
}
return x;
}
Parses the string
bufas a base 10 integer of typeu16.Unlike std.fmt.parseInt, does not allow the '_' character in
buf.