1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn parse_int(comptime T: type, s: ?string, b: u8, d: T) T {
6 if (s == null) return d;
7 return extras.parseDigits(T, s.?, b) catch d;
8}
9
10test {
11 try std.testing.expect(parse_int(u32, "25", 10, 13) == 25);
12}
13test {
14 try std.testing.expect(parse_int(u32, "Q", 10, 13) == 13);
15}
16test {
17 try std.testing.expect(parse_int(u32, "", 10, 13) == 13);
18}
19test {
20 try std.testing.expect(parse_int(u32, null, 10, 13) == 13);
21}