| ... | ... | @@ -860,46 +860,46 @@ pub fn printInt( |
| 860 | 860 | options: std.fmt.Options, |
| 861 | 861 | value: anytype, |
| 862 | 862 | ) anyerror!void { |
| 863 | | comptime var base = 10; |
| 864 | | comptime var case: std.fmt.Case = .lower; |
| 865 | | |
| 866 | 863 | const int_value = if (@TypeOf(value) == comptime_int) blk: { |
| 867 | 864 | const Int = std.math.IntFittingRange(value, value); |
| 868 | 865 | break :blk @as(Int, value); |
| 869 | 866 | } else value; |
| 870 | 867 | |
| 871 | | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) { |
| 872 | | base = 10; |
| 873 | | case = .lower; |
| 874 | | } else if (comptime std.mem.eql(u8, fmt, "c")) { |
| 875 | | if (@typeInfo(@TypeOf(int_value)).int.bits <= 8) { |
| 876 | | return printAsciiChar(bw, @as(u8, int_value), options); |
| 877 | | } else { |
| 878 | | @compileError("cannot print integer that is larger than 8 bits as an ASCII character"); |
| 879 | | } |
| 880 | | } else if (comptime std.mem.eql(u8, fmt, "u")) { |
| 881 | | if (@typeInfo(@TypeOf(int_value)).int.bits <= 21) { |
| 882 | | return printUnicodeCodepoint(bw, @as(u21, int_value), options); |
| 883 | | } else { |
| 884 | | @compileError("cannot print integer that is larger than 21 bits as an UTF-8 sequence"); |
| 885 | | } |
| 886 | | } else if (comptime std.mem.eql(u8, fmt, "b")) { |
| 887 | | base = 2; |
| 888 | | case = .lower; |
| 889 | | } else if (comptime std.mem.eql(u8, fmt, "x")) { |
| 890 | | base = 16; |
| 891 | | case = .lower; |
| 892 | | } else if (comptime std.mem.eql(u8, fmt, "X")) { |
| 893 | | base = 16; |
| 894 | | case = .upper; |
| 895 | | } else if (comptime std.mem.eql(u8, fmt, "o")) { |
| 896 | | base = 8; |
| 897 | | case = .lower; |
| 898 | | } else { |
| 899 | | invalidFmtError(fmt, value); |
| 868 | switch (fmt.len) { |
| 869 | 0 => return printIntOptions(bw, int_value, 10, .lower, options), |
| 870 | 1 => switch (fmt[0]) { |
| 871 | 'd' => return printIntOptions(bw, int_value, 10, .lower, options), |
| 872 | 'c' => { |
| 873 | if (@typeInfo(@TypeOf(int_value)).int.bits <= 8) { |
| 874 | return printAsciiChar(bw, @as(u8, int_value), options); |
| 875 | } else { |
| 876 | @compileError("cannot print integer that is larger than 8 bits as an ASCII character"); |
| 877 | } |
| 878 | }, |
| 879 | 'u' => { |
| 880 | if (@typeInfo(@TypeOf(int_value)).int.bits <= 21) { |
| 881 | return printUnicodeCodepoint(bw, @as(u21, int_value), options); |
| 882 | } else { |
| 883 | @compileError("cannot print integer that is larger than 21 bits as an UTF-8 sequence"); |
| 884 | } |
| 885 | }, |
| 886 | 'b' => return printIntOptions(bw, int_value, 2, .lower, options), |
| 887 | 'x' => return printIntOptions(bw, int_value, 16, .lower, options), |
| 888 | 'X' => return printIntOptions(bw, int_value, 16, .upper, options), |
| 889 | 'o' => return printIntOptions(bw, int_value, 8, .lower, options), |
| 890 | 'B' => return printByteSize(bw, int_value, .decimal, options), |
| 891 | else => invalidFmtError(fmt, value), |
| 892 | }, |
| 893 | 2 => { |
| 894 | if (fmt[0] == 'B' and fmt[1] == 'i') { |
| 895 | return printByteSize(bw, int_value, .binary, options); |
| 896 | } else { |
| 897 | invalidFmtError(fmt, value); |
| 898 | } |
| 899 | }, |
| 900 | else => invalidFmtError(fmt, value), |
| 900 | 901 | } |
| 901 | | |
| 902 | | return printIntOptions(bw, int_value, base, case, options); |
| 902 | comptime unreachable; |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | pub fn printAsciiChar(bw: *BufferedWriter, c: u8, options: std.fmt.Options) anyerror!void { |
| ... | ... | @@ -1128,7 +1128,7 @@ pub const ByteSizeUnits = enum { |
| 1128 | 1128 | pub fn printByteSize( |
| 1129 | 1129 | bw: *std.io.BufferedWriter, |
| 1130 | 1130 | value: u64, |
| 1131 | | units: ByteSizeUnits, |
| 1131 | comptime units: ByteSizeUnits, |
| 1132 | 1132 | options: std.fmt.Options, |
| 1133 | 1133 | ) anyerror!void { |
| 1134 | 1134 | if (value == 0) return alignBufferOptions(bw, "0B", options); |