authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2021-04-10 21:09:38+10:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-10 08:33:42+03:00
log916b645fc1a17f46bab35b54832e037fcf2ab92b
tree7ebdf361125b2d13d347713418d3ad08e29ef1f5
parentb82d6422ac5c0a68b812319f689b66b52b0eaf59

Have std.fmt functions take case as an enum


9 files changed, 88 insertions(+), 86 deletions(-)

lib/std/fmt.zig+48-46
...@@ -370,15 +370,15 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T...@@ -370,15 +370,15 @@ pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @T
370 .Pointer => |info| {370 .Pointer => |info| {
371 try writer.writeAll(@typeName(info.child) ++ "@");371 try writer.writeAll(@typeName(info.child) ++ "@");
372 if (info.size == .Slice)372 if (info.size == .Slice)
373 try formatInt(@ptrToInt(value.ptr), 16, false, FormatOptions{}, writer)373 try formatInt(@ptrToInt(value.ptr), 16, .lower, FormatOptions{}, writer)
374 else374 else
375 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);375 try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
376 return;376 return;
377 },377 },
378 .Optional => |info| {378 .Optional => |info| {
379 if (@typeInfo(info.child) == .Pointer) {379 if (@typeInfo(info.child) == .Pointer) {
380 try writer.writeAll(@typeName(info.child) ++ "@");380 try writer.writeAll(@typeName(info.child) ++ "@");
381 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);381 try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
382 return;382 return;
383 }383 }
384 },384 },
...@@ -651,7 +651,7 @@ pub fn formatIntValue(...@@ -651,7 +651,7 @@ pub fn formatIntValue(
651 writer: anytype,651 writer: anytype,
652) !void {652) !void {
653 comptime var radix = 10;653 comptime var radix = 10;
654 comptime var uppercase = false;654 comptime var case: Case = .lower;
655655
656 const int_value = if (@TypeOf(value) == comptime_int) blk: {656 const int_value = if (@TypeOf(value) == comptime_int) blk: {
657 const Int = math.IntFittingRange(value, value);657 const Int = math.IntFittingRange(value, value);
...@@ -660,7 +660,7 @@ pub fn formatIntValue(...@@ -660,7 +660,7 @@ pub fn formatIntValue(
660660
661 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {661 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {
662 radix = 10;662 radix = 10;
663 uppercase = false;663 case = .lower;
664 } else if (comptime std.mem.eql(u8, fmt, "c")) {664 } else if (comptime std.mem.eql(u8, fmt, "c")) {
665 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {665 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {
666 return formatAsciiChar(@as(u8, int_value), options, writer);666 return formatAsciiChar(@as(u8, int_value), options, writer);
...@@ -675,21 +675,21 @@ pub fn formatIntValue(...@@ -675,21 +675,21 @@ pub fn formatIntValue(
675 }675 }
676 } else if (comptime std.mem.eql(u8, fmt, "b")) {676 } else if (comptime std.mem.eql(u8, fmt, "b")) {
677 radix = 2;677 radix = 2;
678 uppercase = false;678 case = .lower;
679 } else if (comptime std.mem.eql(u8, fmt, "x")) {679 } else if (comptime std.mem.eql(u8, fmt, "x")) {
680 radix = 16;680 radix = 16;
681 uppercase = false;681 case = .lower;
682 } else if (comptime std.mem.eql(u8, fmt, "X")) {682 } else if (comptime std.mem.eql(u8, fmt, "X")) {
683 radix = 16;683 radix = 16;
684 uppercase = true;684 case = .upper;
685 } else if (comptime std.mem.eql(u8, fmt, "o")) {685 } else if (comptime std.mem.eql(u8, fmt, "o")) {
686 radix = 8;686 radix = 8;
687 uppercase = false;687 case = .lower;
688 } else {688 } else {
689 @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");689 @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
690 }690 }
691691
692 return formatInt(int_value, radix, uppercase, options, writer);692 return formatInt(int_value, radix, case, options, writer);
693}693}
694694
695fn formatFloatValue(695fn formatFloatValue(
...@@ -724,8 +724,10 @@ fn formatFloatValue(...@@ -724,8 +724,10 @@ fn formatFloatValue(
724 return formatBuf(buf_stream.getWritten(), options, writer);724 return formatBuf(buf_stream.getWritten(), options, writer);
725}725}
726726
727fn formatSliceHexImpl(comptime uppercase: bool) type {727pub const Case = enum { lower, upper };
728 const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";728
729fn formatSliceHexImpl(comptime case: Case) type {
730 const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
729731
730 return struct {732 return struct {
731 pub fn f(733 pub fn f(
...@@ -745,8 +747,8 @@ fn formatSliceHexImpl(comptime uppercase: bool) type {...@@ -745,8 +747,8 @@ fn formatSliceHexImpl(comptime uppercase: bool) type {
745 };747 };
746}748}
747749
748const formatSliceHexLower = formatSliceHexImpl(false).f;750const formatSliceHexLower = formatSliceHexImpl(.lower).f;
749const formatSliceHexUpper = formatSliceHexImpl(true).f;751const formatSliceHexUpper = formatSliceHexImpl(.upper).f;
750752
751/// Return a Formatter for a []const u8 where every byte is formatted as a pair753/// Return a Formatter for a []const u8 where every byte is formatted as a pair
752/// of lowercase hexadecimal digits.754/// of lowercase hexadecimal digits.
...@@ -754,14 +756,14 @@ pub fn fmtSliceHexLower(bytes: []const u8) std.fmt.Formatter(formatSliceHexLower...@@ -754,14 +756,14 @@ pub fn fmtSliceHexLower(bytes: []const u8) std.fmt.Formatter(formatSliceHexLower
754 return .{ .data = bytes };756 return .{ .data = bytes };
755}757}
756758
757/// Return a Formatter for a []const u8 where every byte is formatted as a pair759/// Return a Formatter for a []const u8 where every byte is formatted as pair
758/// of uppercase hexadecimal digits.760/// of uppercase hexadecimal digits.
759pub fn fmtSliceHexUpper(bytes: []const u8) std.fmt.Formatter(formatSliceHexUpper) {761pub fn fmtSliceHexUpper(bytes: []const u8) std.fmt.Formatter(formatSliceHexUpper) {
760 return .{ .data = bytes };762 return .{ .data = bytes };
761}763}
762764
763fn formatSliceEscapeImpl(comptime uppercase: bool) type {765fn formatSliceEscapeImpl(comptime case: Case) type {
764 const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";766 const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
765767
766 return struct {768 return struct {
767 pub fn f(769 pub fn f(
...@@ -788,8 +790,8 @@ fn formatSliceEscapeImpl(comptime uppercase: bool) type {...@@ -788,8 +790,8 @@ fn formatSliceEscapeImpl(comptime uppercase: bool) type {
788 };790 };
789}791}
790792
791const formatSliceEscapeLower = formatSliceEscapeImpl(false).f;793const formatSliceEscapeLower = formatSliceEscapeImpl(.lower).f;
792const formatSliceEscapeUpper = formatSliceEscapeImpl(true).f;794const formatSliceEscapeUpper = formatSliceEscapeImpl(.upper).f;
793795
794/// Return a Formatter for a []const u8 where every non-printable ASCII796/// Return a Formatter for a []const u8 where every non-printable ASCII
795/// character is escaped as \xNN, where NN is the character in lowercase797/// character is escaped as \xNN, where NN is the character in lowercase
...@@ -1034,13 +1036,13 @@ pub fn formatFloatScientific(...@@ -1034,13 +1036,13 @@ pub fn formatFloatScientific(
1034 if (exp > -10 and exp < 10) {1036 if (exp > -10 and exp < 10) {
1035 try writer.writeAll("0");1037 try writer.writeAll("0");
1036 }1038 }
1037 try formatInt(exp, 10, false, FormatOptions{ .width = 0 }, writer);1039 try formatInt(exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
1038 } else {1040 } else {
1039 try writer.writeAll("-");1041 try writer.writeAll("-");
1040 if (exp > -10 and exp < 10) {1042 if (exp > -10 and exp < 10) {
1041 try writer.writeAll("0");1043 try writer.writeAll("0");
1042 }1044 }
1043 try formatInt(-exp, 10, false, FormatOptions{ .width = 0 }, writer);1045 try formatInt(-exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
1044 }1046 }
1045}1047}
10461048
...@@ -1133,7 +1135,7 @@ pub fn formatFloatHexadecimal(...@@ -1133,7 +1135,7 @@ pub fn formatFloatHexadecimal(
11331135
1134 // +1 for the decimal part.1136 // +1 for the decimal part.
1135 var buf: [1 + mantissa_digits]u8 = undefined;1137 var buf: [1 + mantissa_digits]u8 = undefined;
1136 const N = formatIntBuf(&buf, mantissa, 16, false, .{ .fill = '0', .width = 1 + mantissa_digits });1138 const N = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
11371139
1138 try writer.writeAll("0x");1140 try writer.writeAll("0x");
1139 try writer.writeByte(buf[0]);1141 try writer.writeByte(buf[0]);
...@@ -1150,7 +1152,7 @@ pub fn formatFloatHexadecimal(...@@ -1150,7 +1152,7 @@ pub fn formatFloatHexadecimal(
1150 try writer.writeByteNTimes('0', precision - trimmed.len);1152 try writer.writeByteNTimes('0', precision - trimmed.len);
1151 };1153 };
1152 try writer.writeAll("p");1154 try writer.writeAll("p");
1153 try formatInt(exponent - exponent_bias, 10, false, .{}, writer);1155 try formatInt(exponent - exponent_bias, 10, .lower, .{}, writer);
1154}1156}
11551157
1156/// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.1158/// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
...@@ -1299,7 +1301,7 @@ pub fn formatFloatDecimal(...@@ -1299,7 +1301,7 @@ pub fn formatFloatDecimal(
1299pub fn formatInt(1301pub fn formatInt(
1300 value: anytype,1302 value: anytype,
1301 base: u8,1303 base: u8,
1302 uppercase: bool,1304 case: Case,
1303 options: FormatOptions,1305 options: FormatOptions,
1304 writer: anytype,1306 writer: anytype,
1305) !void {1307) !void {
...@@ -1326,7 +1328,7 @@ pub fn formatInt(...@@ -1326,7 +1328,7 @@ pub fn formatInt(
1326 while (true) {1328 while (true) {
1327 const digit = a % base;1329 const digit = a % base;
1328 index -= 1;1330 index -= 1;
1329 buf[index] = digitToChar(@intCast(u8, digit), uppercase);1331 buf[index] = digitToChar(@intCast(u8, digit), case);
1330 a /= base;1332 a /= base;
1331 if (a == 0) break;1333 if (a == 0) break;
1332 }1334 }
...@@ -1348,9 +1350,9 @@ pub fn formatInt(...@@ -1348,9 +1350,9 @@ pub fn formatInt(
1348 return formatBuf(buf[index..], options, writer);1350 return formatBuf(buf[index..], options, writer);
1349}1351}
13501352
1351pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) usize {1353pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) usize {
1352 var fbs = std.io.fixedBufferStream(out_buf);1354 var fbs = std.io.fixedBufferStream(out_buf);
1353 formatInt(value, base, uppercase, options, fbs.writer()) catch unreachable;1355 formatInt(value, base, case, options, fbs.writer()) catch unreachable;
1354 return fbs.pos;1356 return fbs.pos;
1355}1357}
13561358
...@@ -1365,7 +1367,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti...@@ -1365,7 +1367,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
1365 }) |unit| {1367 }) |unit| {
1366 if (ns_remaining >= unit.ns) {1368 if (ns_remaining >= unit.ns) {
1367 const units = ns_remaining / unit.ns;1369 const units = ns_remaining / unit.ns;
1368 try formatInt(units, 10, false, .{}, writer);1370 try formatInt(units, 10, .lower, .{}, writer);
1369 try writer.writeByte(unit.sep);1371 try writer.writeByte(unit.sep);
1370 ns_remaining -= units * unit.ns;1372 ns_remaining -= units * unit.ns;
1371 if (ns_remaining == 0) return;1373 if (ns_remaining == 0) return;
...@@ -1379,12 +1381,12 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti...@@ -1379,12 +1381,12 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
1379 }) |unit| {1381 }) |unit| {
1380 const kunits = ns_remaining * 1000 / unit.ns;1382 const kunits = ns_remaining * 1000 / unit.ns;
1381 if (kunits >= 1000) {1383 if (kunits >= 1000) {
1382 try formatInt(kunits / 1000, 10, false, .{}, writer);1384 try formatInt(kunits / 1000, 10, .lower, .{}, writer);
1383 const frac = kunits % 1000;1385 const frac = kunits % 1000;
1384 if (frac > 0) {1386 if (frac > 0) {
1385 // Write up to 3 decimal places1387 // Write up to 3 decimal places
1386 var buf = [_]u8{ '.', 0, 0, 0 };1388 var buf = [_]u8{ '.', 0, 0, 0 };
1387 _ = formatIntBuf(buf[1..], frac, 10, false, .{ .fill = '0', .width = 3 });1389 _ = formatIntBuf(buf[1..], frac, 10, .lower, .{ .fill = '0', .width = 3 });
1388 var end: usize = 4;1390 var end: usize = 4;
1389 while (end > 1) : (end -= 1) {1391 while (end > 1) : (end -= 1) {
1390 if (buf[end - 1] != '0') break;1392 if (buf[end - 1] != '0') break;
...@@ -1396,7 +1398,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti...@@ -1396,7 +1398,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
1396 }1398 }
1397 }1399 }
13981400
1399 try formatInt(ns_remaining, 10, false, .{}, writer);1401 try formatInt(ns_remaining, 10, .lower, .{}, writer);
1400 try writer.writeAll("ns");1402 try writer.writeAll("ns");
1401 return;1403 return;
1402}1404}
...@@ -1673,10 +1675,10 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {...@@ -1673,10 +1675,10 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
1673 return value;1675 return value;
1674}1676}
16751677
1676pub fn digitToChar(digit: u8, uppercase: bool) u8 {1678pub fn digitToChar(digit: u8, case: Case) u8 {
1677 return switch (digit) {1679 return switch (digit) {
1678 0...9 => digit + '0',1680 0...9 => digit + '0',
1679 10...35 => digit + ((if (uppercase) @as(u8, 'A') else @as(u8, 'a')) - 10),1681 10...35 => digit + ((if (case == .upper) @as(u8, 'A') else @as(u8, 'a')) - 10),
1680 else => unreachable,1682 else => unreachable,
1681 };1683 };
1682}1684}
...@@ -1728,25 +1730,25 @@ test "bufPrintInt" {...@@ -1728,25 +1730,25 @@ test "bufPrintInt" {
1728 var buffer: [100]u8 = undefined;1730 var buffer: [100]u8 = undefined;
1729 const buf = buffer[0..];1731 const buf = buffer[0..];
17301732
1731 try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, false, FormatOptions{}));1733 try std.testing.expectEqualSlices(u8, "-1", bufPrintIntToSlice(buf, @as(i1, -1), 10, .lower, FormatOptions{}));
17321734
1733 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, false, FormatOptions{}));1735 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, .lower, FormatOptions{}));
1734 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));1736 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, .lower, FormatOptions{}));
1735 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));1737 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, .lower, FormatOptions{}));
1736 try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));1738 try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, .upper, FormatOptions{}));
17371739
1738 try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, true, FormatOptions{}));1740 try std.testing.expectEqualSlices(u8, "12345678", bufPrintIntToSlice(buf, @as(u32, 12345678), 10, .upper, FormatOptions{}));
17391741
1740 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, false, FormatOptions{ .width = 6 }));1742 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, .lower, FormatOptions{ .width = 6 }));
1741 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));1743 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, .lower, FormatOptions{ .width = 6 }));
1742 try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));1744 try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, .lower, FormatOptions{ .width = 1 }));
17431745
1744 try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, false, FormatOptions{ .width = 3 }));1746 try std.testing.expectEqualSlices(u8, "+42", bufPrintIntToSlice(buf, @as(i32, 42), 10, .lower, FormatOptions{ .width = 3 }));
1745 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));1747 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, .lower, FormatOptions{ .width = 3 }));
1746}1748}
17471749
1748pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {1750pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) []u8 {
1749 return buf[0..formatIntBuf(buf, value, base, uppercase, options)];1751 return buf[0..formatIntBuf(buf, value, base, case, options)];
1750}1752}
17511753
1752pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 {1754pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 {
lib/std/math/big/int.zig+14-14
...@@ -1140,20 +1140,20 @@ pub const Const = struct {...@@ -1140,20 +1140,20 @@ pub const Const = struct {
1140 out_stream: anytype,1140 out_stream: anytype,
1141 ) !void {1141 ) !void {
1142 comptime var radix = 10;1142 comptime var radix = 10;
1143 comptime var uppercase = false;1143 comptime var case: std.fmt.Case = .lower;
11441144
1145 if (fmt.len == 0 or comptime mem.eql(u8, fmt, "d")) {1145 if (fmt.len == 0 or comptime mem.eql(u8, fmt, "d")) {
1146 radix = 10;1146 radix = 10;
1147 uppercase = false;1147 case = .lower;
1148 } else if (comptime mem.eql(u8, fmt, "b")) {1148 } else if (comptime mem.eql(u8, fmt, "b")) {
1149 radix = 2;1149 radix = 2;
1150 uppercase = false;1150 case = .lower;
1151 } else if (comptime mem.eql(u8, fmt, "x")) {1151 } else if (comptime mem.eql(u8, fmt, "x")) {
1152 radix = 16;1152 radix = 16;
1153 uppercase = false;1153 case = .lower;
1154 } else if (comptime mem.eql(u8, fmt, "X")) {1154 } else if (comptime mem.eql(u8, fmt, "X")) {
1155 radix = 16;1155 radix = 16;
1156 uppercase = true;1156 case = .upper;
1157 } else {1157 } else {
1158 @compileError("Unknown format string: '" ++ fmt ++ "'");1158 @compileError("Unknown format string: '" ++ fmt ++ "'");
1159 }1159 }
...@@ -1171,7 +1171,7 @@ pub const Const = struct {...@@ -1171,7 +1171,7 @@ pub const Const = struct {
1171 .positive = false,1171 .positive = false,
1172 };1172 };
1173 var buf: [biggest.sizeInBaseUpperBound(radix)]u8 = undefined;1173 var buf: [biggest.sizeInBaseUpperBound(radix)]u8 = undefined;
1174 const len = self.toString(&buf, radix, uppercase, &limbs);1174 const len = self.toString(&buf, radix, case, &limbs);
1175 return out_stream.writeAll(buf[0..len]);1175 return out_stream.writeAll(buf[0..len]);
1176 }1176 }
11771177
...@@ -1179,7 +1179,7 @@ pub const Const = struct {...@@ -1179,7 +1179,7 @@ pub const Const = struct {
1179 /// Caller owns returned memory.1179 /// Caller owns returned memory.
1180 /// Asserts that `base` is in the range [2, 16].1180 /// Asserts that `base` is in the range [2, 16].
1181 /// See also `toString`, a lower level function than this.1181 /// See also `toString`, a lower level function than this.
1182 pub fn toStringAlloc(self: Const, allocator: *Allocator, base: u8, uppercase: bool) Allocator.Error![]u8 {1182 pub fn toStringAlloc(self: Const, allocator: *Allocator, base: u8, case: std.fmt.Case) Allocator.Error![]u8 {
1183 assert(base >= 2);1183 assert(base >= 2);
1184 assert(base <= 16);1184 assert(base <= 16);
11851185
...@@ -1192,7 +1192,7 @@ pub const Const = struct {...@@ -1192,7 +1192,7 @@ pub const Const = struct {
1192 const limbs = try allocator.alloc(Limb, calcToStringLimbsBufferLen(self.limbs.len, base));1192 const limbs = try allocator.alloc(Limb, calcToStringLimbsBufferLen(self.limbs.len, base));
1193 defer allocator.free(limbs);1193 defer allocator.free(limbs);
11941194
1195 return allocator.shrink(string, self.toString(string, base, uppercase, limbs));1195 return allocator.shrink(string, self.toString(string, base, case, limbs));
1196 }1196 }
11971197
1198 /// Converts self to a string in the requested base.1198 /// Converts self to a string in the requested base.
...@@ -1204,7 +1204,7 @@ pub const Const = struct {...@@ -1204,7 +1204,7 @@ pub const Const = struct {
1204 /// length of at least `calcToStringLimbsBufferLen`.1204 /// length of at least `calcToStringLimbsBufferLen`.
1205 /// In the case of power-of-two base, `limbs_buffer` is ignored.1205 /// In the case of power-of-two base, `limbs_buffer` is ignored.
1206 /// See also `toStringAlloc`, a higher level function than this.1206 /// See also `toStringAlloc`, a higher level function than this.
1207 pub fn toString(self: Const, string: []u8, base: u8, uppercase: bool, limbs_buffer: []Limb) usize {1207 pub fn toString(self: Const, string: []u8, base: u8, case: std.fmt.Case, limbs_buffer: []Limb) usize {
1208 assert(base >= 2);1208 assert(base >= 2);
1209 assert(base <= 16);1209 assert(base <= 16);
12101210
...@@ -1223,7 +1223,7 @@ pub const Const = struct {...@@ -1223,7 +1223,7 @@ pub const Const = struct {
1223 var shift: usize = 0;1223 var shift: usize = 0;
1224 while (shift < limb_bits) : (shift += base_shift) {1224 while (shift < limb_bits) : (shift += base_shift) {
1225 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));1225 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
1226 const ch = std.fmt.digitToChar(r, uppercase);1226 const ch = std.fmt.digitToChar(r, case);
1227 string[digits_len] = ch;1227 string[digits_len] = ch;
1228 digits_len += 1;1228 digits_len += 1;
1229 // If we hit the end, it must be all zeroes from here.1229 // If we hit the end, it must be all zeroes from here.
...@@ -1269,7 +1269,7 @@ pub const Const = struct {...@@ -1269,7 +1269,7 @@ pub const Const = struct {
1269 var r_word = r.limbs[0];1269 var r_word = r.limbs[0];
1270 var i: usize = 0;1270 var i: usize = 0;
1271 while (i < digits_per_limb) : (i += 1) {1271 while (i < digits_per_limb) : (i += 1) {
1272 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), uppercase);1272 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), case);
1273 r_word /= base;1273 r_word /= base;
1274 string[digits_len] = ch;1274 string[digits_len] = ch;
1275 digits_len += 1;1275 digits_len += 1;
...@@ -1281,7 +1281,7 @@ pub const Const = struct {...@@ -1281,7 +1281,7 @@ pub const Const = struct {
12811281
1282 var r_word = q.limbs[0];1282 var r_word = q.limbs[0];
1283 while (r_word != 0) {1283 while (r_word != 0) {
1284 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), uppercase);1284 const ch = std.fmt.digitToChar(@intCast(u8, r_word % base), case);
1285 r_word /= base;1285 r_word /= base;
1286 string[digits_len] = ch;1286 string[digits_len] = ch;
1287 digits_len += 1;1287 digits_len += 1;
...@@ -1615,9 +1615,9 @@ pub const Managed = struct {...@@ -1615,9 +1615,9 @@ pub const Managed = struct {
16151615
1616 /// Converts self to a string in the requested base. Memory is allocated from the provided1616 /// Converts self to a string in the requested base. Memory is allocated from the provided
1617 /// allocator and not the one present in self.1617 /// allocator and not the one present in self.
1618 pub fn toString(self: Managed, allocator: *Allocator, base: u8, uppercase: bool) ![]u8 {1618 pub fn toString(self: Managed, allocator: *Allocator, base: u8, case: std.fmt.Case) ![]u8 {
1619 if (base < 2 or base > 16) return error.InvalidBase;1619 if (base < 2 or base > 16) return error.InvalidBase;
1620 return self.toConst().toStringAlloc(self.allocator, base, uppercase);1620 return self.toConst().toStringAlloc(self.allocator, base, case);
1621 }1621 }
16221622
1623 /// To allow `std.fmt.format` to work with `Managed`.1623 /// To allow `std.fmt.format` to work with `Managed`.
lib/std/math/big/int_test.zig+15-15
...@@ -277,7 +277,7 @@ test "big.int string to" {...@@ -277,7 +277,7 @@ test "big.int string to" {
277 var a = try Managed.initSet(testing.allocator, 120317241209124781241290847124);277 var a = try Managed.initSet(testing.allocator, 120317241209124781241290847124);
278 defer a.deinit();278 defer a.deinit();
279279
280 const as = try a.toString(testing.allocator, 10, false);280 const as = try a.toString(testing.allocator, 10, .lower);
281 defer testing.allocator.free(as);281 defer testing.allocator.free(as);
282 const es = "120317241209124781241290847124";282 const es = "120317241209124781241290847124";
283283
...@@ -288,14 +288,14 @@ test "big.int string to base base error" {...@@ -288,14 +288,14 @@ test "big.int string to base base error" {
288 var a = try Managed.initSet(testing.allocator, 0xffffffff);288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289 defer a.deinit();289 defer a.deinit();
290290
291 try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, false));291 try testing.expectError(error.InvalidBase, a.toString(testing.allocator, 45, .lower));
292}292}
293293
294test "big.int string to base 2" {294test "big.int string to base 2" {
295 var a = try Managed.initSet(testing.allocator, -0b1011);295 var a = try Managed.initSet(testing.allocator, -0b1011);
296 defer a.deinit();296 defer a.deinit();
297297
298 const as = try a.toString(testing.allocator, 2, false);298 const as = try a.toString(testing.allocator, 2, .lower);
299 defer testing.allocator.free(as);299 defer testing.allocator.free(as);
300 const es = "-1011";300 const es = "-1011";
301301
...@@ -306,7 +306,7 @@ test "big.int string to base 16" {...@@ -306,7 +306,7 @@ test "big.int string to base 16" {
306 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);306 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
307 defer a.deinit();307 defer a.deinit();
308308
309 const as = try a.toString(testing.allocator, 16, false);309 const as = try a.toString(testing.allocator, 16, .lower);
310 defer testing.allocator.free(as);310 defer testing.allocator.free(as);
311 const es = "efffffff00000001eeeeeeefaaaaaaab";311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
...@@ -317,7 +317,7 @@ test "big.int neg string to" {...@@ -317,7 +317,7 @@ test "big.int neg string to" {
317 var a = try Managed.initSet(testing.allocator, -123907434);317 var a = try Managed.initSet(testing.allocator, -123907434);
318 defer a.deinit();318 defer a.deinit();
319319
320 const as = try a.toString(testing.allocator, 10, false);320 const as = try a.toString(testing.allocator, 10, .lower);
321 defer testing.allocator.free(as);321 defer testing.allocator.free(as);
322 const es = "-123907434";322 const es = "-123907434";
323323
...@@ -328,7 +328,7 @@ test "big.int zero string to" {...@@ -328,7 +328,7 @@ test "big.int zero string to" {
328 var a = try Managed.initSet(testing.allocator, 0);328 var a = try Managed.initSet(testing.allocator, 0);
329 defer a.deinit();329 defer a.deinit();
330330
331 const as = try a.toString(testing.allocator, 10, false);331 const as = try a.toString(testing.allocator, 10, .lower);
332 defer testing.allocator.free(as);332 defer testing.allocator.free(as);
333 const es = "0";333 const es = "0";
334334
...@@ -1180,7 +1180,7 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {...@@ -1180,7 +1180,7 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
11801180
1181 try testing.expect((try q.to(u128)) == 0x10000000000000000);1181 try testing.expect((try q.to(u128)) == 0x10000000000000000);
11821182
1183 const rs = try r.toString(testing.allocator, 16, false);1183 const rs = try r.toString(testing.allocator, 16, .lower);
1184 defer testing.allocator.free(rs);1184 defer testing.allocator.free(rs);
1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));1185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1186}1186}
...@@ -1199,7 +1199,7 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li...@@ -1199,7 +1199,7 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
11991199
1200 try testing.expect((try q.to(u128)) == 0x1);1200 try testing.expect((try q.to(u128)) == 0x1);
12011201
1202 const rs = try r.toString(testing.allocator, 16, false);1202 const rs = try r.toString(testing.allocator, 16, .lower);
1203 defer testing.allocator.free(rs);1203 defer testing.allocator.free(rs);
1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));1204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1205}1205}
...@@ -1216,11 +1216,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li...@@ -1216,11 +1216,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
1216 defer r.deinit();1216 defer r.deinit();
1217 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1217 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
12181218
1219 const qs = try q.toString(testing.allocator, 16, false);1219 const qs = try q.toString(testing.allocator, 16, .lower);
1220 defer testing.allocator.free(qs);1220 defer testing.allocator.free(qs);
1221 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));1221 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
12221222
1223 const rs = try r.toString(testing.allocator, 16, false);1223 const rs = try r.toString(testing.allocator, 16, .lower);
1224 defer testing.allocator.free(rs);1224 defer testing.allocator.free(rs);
1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));1225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1226}1226}
...@@ -1240,11 +1240,11 @@ test "big.int div multi-multi fuzz case #1" {...@@ -1240,11 +1240,11 @@ test "big.int div multi-multi fuzz case #1" {
1240 defer r.deinit();1240 defer r.deinit();
1241 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1241 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
12421242
1243 const qs = try q.toString(testing.allocator, 16, false);1243 const qs = try q.toString(testing.allocator, 16, .lower);
1244 defer testing.allocator.free(qs);1244 defer testing.allocator.free(qs);
1245 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));1245 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
12461246
1247 const rs = try r.toString(testing.allocator, 16, false);1247 const rs = try r.toString(testing.allocator, 16, .lower);
1248 defer testing.allocator.free(rs);1248 defer testing.allocator.free(rs);
1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));1249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1250}1250}
...@@ -1264,11 +1264,11 @@ test "big.int div multi-multi fuzz case #2" {...@@ -1264,11 +1264,11 @@ test "big.int div multi-multi fuzz case #2" {
1264 defer r.deinit();1264 defer r.deinit();
1265 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());1265 try Managed.divTrunc(&q, &r, a.toConst(), b.toConst());
12661266
1267 const qs = try q.toString(testing.allocator, 16, false);1267 const qs = try q.toString(testing.allocator, 16, .lower);
1268 defer testing.allocator.free(qs);1268 defer testing.allocator.free(qs);
1269 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));1269 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
12701270
1271 const rs = try r.toString(testing.allocator, 16, false);1271 const rs = try r.toString(testing.allocator, 16, .lower);
1272 defer testing.allocator.free(rs);1272 defer testing.allocator.free(rs);
1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));1273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1274}1274}
...@@ -1533,7 +1533,7 @@ test "big.int pow" {...@@ -1533,7 +1533,7 @@ test "big.int pow" {
15331533
1534 try testing.expect(a.eq(y));1534 try testing.expect(a.eq(y));
15351535
1536 const ys = try y.toString(testing.allocator, 16, false);1536 const ys = try y.toString(testing.allocator, 16, .lower);
1537 defer testing.allocator.free(ys);1537 defer testing.allocator.free(ys);
1538 try testing.expectEqualSlices(1538 try testing.expectEqualSlices(
1539 u8,1539 u8,
lib/std/zig/fmt.zig+1-1
...@@ -68,7 +68,7 @@ pub fn formatEscapes(...@@ -68,7 +68,7 @@ pub fn formatEscapes(
68 // Use hex escapes for rest any unprintable characters.68 // Use hex escapes for rest any unprintable characters.
69 else => {69 else => {
70 try writer.writeAll("\\x");70 try writer.writeAll("\\x");
71 try std.fmt.formatInt(byte, 16, false, .{ .width = 2, .fill = '0' }, writer);71 try std.fmt.formatInt(byte, 16, .lower, .{ .width = 2, .fill = '0' }, writer);
72 },72 },
73 };73 };
74}74}
src/Compilation.zig+1-1
...@@ -4009,7 +4009,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -4009,7 +4009,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
4009 });4009 });
4010 var digest_plus_flags: [digest.len + 2]u8 = undefined;4010 var digest_plus_flags: [digest.len + 2]u8 = undefined;
4011 digest_plus_flags[0..digest.len].* = digest;4011 digest_plus_flags[0..digest.len].* = digest;
4012 assert(std.fmt.formatIntBuf(digest_plus_flags[digest.len..], stage1_flags_byte, 16, false, .{4012 assert(std.fmt.formatIntBuf(digest_plus_flags[digest.len..], stage1_flags_byte, 16, .lower, .{
4013 .width = 2,4013 .width = 2,
4014 .fill = '0',4014 .fill = '0',
4015 }) == 2);4015 }) == 2);
src/DepTokenizer.zig+2-2
...@@ -1026,13 +1026,13 @@ fn hexDump16(out: anytype, offset: usize, bytes: []const u8) !void {...@@ -1026,13 +1026,13 @@ fn hexDump16(out: anytype, offset: usize, bytes: []const u8) !void {
10261026
1027fn printDecValue(out: anytype, value: u64, width: u8) !void {1027fn printDecValue(out: anytype, value: u64, width: u8) !void {
1028 var buffer: [20]u8 = undefined;1028 var buffer: [20]u8 = undefined;
1029 const len = std.fmt.formatIntBuf(buffer[0..], value, 10, false, .{ .width = width, .fill = '0' });1029 const len = std.fmt.formatIntBuf(buffer[0..], value, 10, .lower, .{ .width = width, .fill = '0' });
1030 try out.writeAll(buffer[0..len]);1030 try out.writeAll(buffer[0..len]);
1031}1031}
10321032
1033fn printHexValue(out: anytype, value: u64, width: u8) !void {1033fn printHexValue(out: anytype, value: u64, width: u8) !void {
1034 var buffer: [16]u8 = undefined;1034 var buffer: [16]u8 = undefined;
1035 const len = std.fmt.formatIntBuf(buffer[0..], value, 16, false, .{ .width = width, .fill = '0' });1035 const len = std.fmt.formatIntBuf(buffer[0..], value, 16, .lower, .{ .width = width, .fill = '0' });
1036 try out.writeAll(buffer[0..len]);1036 try out.writeAll(buffer[0..len]);
1037}1037}
10381038
src/Zir.zig+1-1
...@@ -3231,7 +3231,7 @@ const Writer = struct {...@@ -3231,7 +3231,7 @@ const Writer = struct {
3231 .limbs = limbs,3231 .limbs = limbs,
3232 .positive = true,3232 .positive = true,
3233 };3233 };
3234 const as_string = try big_int.toStringAlloc(self.gpa, 10, false);3234 const as_string = try big_int.toStringAlloc(self.gpa, 10, .lower);
3235 defer self.gpa.free(as_string);3235 defer self.gpa.free(as_string);
3236 try stream.print("{s})", .{as_string});3236 try stream.print("{s})", .{as_string});
3237 }3237 }
src/translate_c.zig+4-4
...@@ -4146,7 +4146,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {...@@ -4146,7 +4146,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {
4146 }4146 }
41474147
4148 const big: math.big.int.Const = .{ .limbs = limbs, .positive = true };4148 const big: math.big.int.Const = .{ .limbs = limbs, .positive = true };
4149 const str = big.toStringAlloc(c.arena, 10, false) catch |err| switch (err) {4149 const str = big.toStringAlloc(c.arena, 10, .lower) catch |err| switch (err) {
4150 error.OutOfMemory => return error.OutOfMemory,4150 error.OutOfMemory => return error.OutOfMemory,
4151 };4151 };
4152 const res = try Tag.integer_literal.create(c.arena, str);4152 const res = try Tag.integer_literal.create(c.arena, str);
...@@ -5083,7 +5083,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {...@@ -5083,7 +5083,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
5083 num += c - 'A' + 10;5083 num += c - 'A' + 10;
5084 },5084 },
5085 else => {5085 else => {
5086 i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 });5086 i += std.fmt.formatIntBuf(bytes[i..], num, 16, .lower, std.fmt.FormatOptions{ .fill = '0', .width = 2 });
5087 num = 0;5087 num = 0;
5088 if (c == '\\')5088 if (c == '\\')
5089 state = .Escape5089 state = .Escape
...@@ -5109,7 +5109,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {...@@ -5109,7 +5109,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
5109 };5109 };
5110 num += c - '0';5110 num += c - '0';
5111 } else {5111 } else {
5112 i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 });5112 i += std.fmt.formatIntBuf(bytes[i..], num, 16, .lower, std.fmt.FormatOptions{ .fill = '0', .width = 2 });
5113 num = 0;5113 num = 0;
5114 count = 0;5114 count = 0;
5115 if (c == '\\')5115 if (c == '\\')
...@@ -5123,7 +5123,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {...@@ -5123,7 +5123,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
5123 }5123 }
5124 }5124 }
5125 if (state == .Hex or state == .Octal)5125 if (state == .Hex or state == .Octal)
5126 i += std.fmt.formatIntBuf(bytes[i..], num, 16, false, std.fmt.FormatOptions{ .fill = '0', .width = 2 });5126 i += std.fmt.formatIntBuf(bytes[i..], num, 16, .lower, std.fmt.FormatOptions{ .fill = '0', .width = 2 });
5127 return bytes[0..i];5127 return bytes[0..i];
5128}5128}
51295129
test/behavior/enum_with_members.zig+2-2
...@@ -8,8 +8,8 @@ const ET = union(enum) {...@@ -8,8 +8,8 @@ const ET = union(enum) {
88
9 pub fn print(a: *const ET, buf: []u8) anyerror!usize {9 pub fn print(a: *const ET, buf: []u8) anyerror!usize {
10 return switch (a.*) {10 return switch (a.*) {
11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, fmt.FormatOptions{}),11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, .lower, fmt.FormatOptions{}),
12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, fmt.FormatOptions{}),12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, .lower, fmt.FormatOptions{}),
13 };13 };
14 }14 }
15};15};