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
370370 .Pointer => |info| {
371371 try writer.writeAll(@typeName(info.child) ++ "@");
372372 if (info.size == .Slice)
373 try formatInt(@ptrToInt(value.ptr), 16, false, FormatOptions{}, writer)
373 try formatInt(@ptrToInt(value.ptr), 16, .lower, FormatOptions{}, writer)
374374 else
375 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
375 try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
376376 return;
377377 },
378378 .Optional => |info| {
379379 if (@typeInfo(info.child) == .Pointer) {
380380 try writer.writeAll(@typeName(info.child) ++ "@");
381 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
381 try formatInt(@ptrToInt(value), 16, .lower, FormatOptions{}, writer);
382382 return;
383383 }
384384 },
......@@ -651,7 +651,7 @@ pub fn formatIntValue(
651651 writer: anytype,
652652) !void {
653653 comptime var radix = 10;
654 comptime var uppercase = false;
654 comptime var case: Case = .lower;
655655
656656 const int_value = if (@TypeOf(value) == comptime_int) blk: {
657657 const Int = math.IntFittingRange(value, value);
......@@ -660,7 +660,7 @@ pub fn formatIntValue(
660660
661661 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {
662662 radix = 10;
663 uppercase = false;
663 case = .lower;
664664 } else if (comptime std.mem.eql(u8, fmt, "c")) {
665665 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {
666666 return formatAsciiChar(@as(u8, int_value), options, writer);
......@@ -675,21 +675,21 @@ pub fn formatIntValue(
675675 }
676676 } else if (comptime std.mem.eql(u8, fmt, "b")) {
677677 radix = 2;
678 uppercase = false;
678 case = .lower;
679679 } else if (comptime std.mem.eql(u8, fmt, "x")) {
680680 radix = 16;
681 uppercase = false;
681 case = .lower;
682682 } else if (comptime std.mem.eql(u8, fmt, "X")) {
683683 radix = 16;
684 uppercase = true;
684 case = .upper;
685685 } else if (comptime std.mem.eql(u8, fmt, "o")) {
686686 radix = 8;
687 uppercase = false;
687 case = .lower;
688688 } else {
689689 @compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
690690 }
691691
692 return formatInt(int_value, radix, uppercase, options, writer);
692 return formatInt(int_value, radix, case, options, writer);
693693}
694694
695695fn formatFloatValue(
......@@ -724,8 +724,10 @@ fn formatFloatValue(
724724 return formatBuf(buf_stream.getWritten(), options, writer);
725725}
726726
727fn formatSliceHexImpl(comptime uppercase: bool) type {
728 const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
727pub const Case = enum { lower, upper };
728
729fn formatSliceHexImpl(comptime case: Case) type {
730 const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
729731
730732 return struct {
731733 pub fn f(
......@@ -745,8 +747,8 @@ fn formatSliceHexImpl(comptime uppercase: bool) type {
745747 };
746748}
747749
748const formatSliceHexLower = formatSliceHexImpl(false).f;
749const formatSliceHexUpper = formatSliceHexImpl(true).f;
750const formatSliceHexLower = formatSliceHexImpl(.lower).f;
751const formatSliceHexUpper = formatSliceHexImpl(.upper).f;
750752
751753/// Return a Formatter for a []const u8 where every byte is formatted as a pair
752754/// of lowercase hexadecimal digits.
......@@ -754,14 +756,14 @@ pub fn fmtSliceHexLower(bytes: []const u8) std.fmt.Formatter(formatSliceHexLower
754756 return .{ .data = bytes };
755757}
756758
757/// Return a Formatter for a []const u8 where every byte is formatted as a pair
759/// Return a Formatter for a []const u8 where every byte is formatted as pair
758760/// of uppercase hexadecimal digits.
759761pub fn fmtSliceHexUpper(bytes: []const u8) std.fmt.Formatter(formatSliceHexUpper) {
760762 return .{ .data = bytes };
761763}
762764
763fn formatSliceEscapeImpl(comptime uppercase: bool) type {
764 const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
765fn formatSliceEscapeImpl(comptime case: Case) type {
766 const charset = "0123456789" ++ if (case == .upper) "ABCDEF" else "abcdef";
765767
766768 return struct {
767769 pub fn f(
......@@ -788,8 +790,8 @@ fn formatSliceEscapeImpl(comptime uppercase: bool) type {
788790 };
789791}
790792
791const formatSliceEscapeLower = formatSliceEscapeImpl(false).f;
792const formatSliceEscapeUpper = formatSliceEscapeImpl(true).f;
793const formatSliceEscapeLower = formatSliceEscapeImpl(.lower).f;
794const formatSliceEscapeUpper = formatSliceEscapeImpl(.upper).f;
793795
794796/// Return a Formatter for a []const u8 where every non-printable ASCII
795797/// character is escaped as \xNN, where NN is the character in lowercase
......@@ -1034,13 +1036,13 @@ pub fn formatFloatScientific(
10341036 if (exp > -10 and exp < 10) {
10351037 try writer.writeAll("0");
10361038 }
1037 try formatInt(exp, 10, false, FormatOptions{ .width = 0 }, writer);
1039 try formatInt(exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
10381040 } else {
10391041 try writer.writeAll("-");
10401042 if (exp > -10 and exp < 10) {
10411043 try writer.writeAll("0");
10421044 }
1043 try formatInt(-exp, 10, false, FormatOptions{ .width = 0 }, writer);
1045 try formatInt(-exp, 10, .lower, FormatOptions{ .width = 0 }, writer);
10441046 }
10451047}
10461048
......@@ -1133,7 +1135,7 @@ pub fn formatFloatHexadecimal(
11331135
11341136 // +1 for the decimal part.
11351137 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
11381140 try writer.writeAll("0x");
11391141 try writer.writeByte(buf[0]);
......@@ -1150,7 +1152,7 @@ pub fn formatFloatHexadecimal(
11501152 try writer.writeByteNTimes('0', precision - trimmed.len);
11511153 };
11521154 try writer.writeAll("p");
1153 try formatInt(exponent - exponent_bias, 10, false, .{}, writer);
1155 try formatInt(exponent - exponent_bias, 10, .lower, .{}, writer);
11541156}
11551157
11561158/// 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(
12991301pub fn formatInt(
13001302 value: anytype,
13011303 base: u8,
1302 uppercase: bool,
1304 case: Case,
13031305 options: FormatOptions,
13041306 writer: anytype,
13051307) !void {
......@@ -1326,7 +1328,7 @@ pub fn formatInt(
13261328 while (true) {
13271329 const digit = a % base;
13281330 index -= 1;
1329 buf[index] = digitToChar(@intCast(u8, digit), uppercase);
1331 buf[index] = digitToChar(@intCast(u8, digit), case);
13301332 a /= base;
13311333 if (a == 0) break;
13321334 }
......@@ -1348,9 +1350,9 @@ pub fn formatInt(
13481350 return formatBuf(buf[index..], options, writer);
13491351}
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 {
13521354 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;
13541356 return fbs.pos;
13551357}
13561358
......@@ -1365,7 +1367,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13651367 }) |unit| {
13661368 if (ns_remaining >= unit.ns) {
13671369 const units = ns_remaining / unit.ns;
1368 try formatInt(units, 10, false, .{}, writer);
1370 try formatInt(units, 10, .lower, .{}, writer);
13691371 try writer.writeByte(unit.sep);
13701372 ns_remaining -= units * unit.ns;
13711373 if (ns_remaining == 0) return;
......@@ -1379,12 +1381,12 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13791381 }) |unit| {
13801382 const kunits = ns_remaining * 1000 / unit.ns;
13811383 if (kunits >= 1000) {
1382 try formatInt(kunits / 1000, 10, false, .{}, writer);
1384 try formatInt(kunits / 1000, 10, .lower, .{}, writer);
13831385 const frac = kunits % 1000;
13841386 if (frac > 0) {
13851387 // Write up to 3 decimal places
13861388 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 });
13881390 var end: usize = 4;
13891391 while (end > 1) : (end -= 1) {
13901392 if (buf[end - 1] != '0') break;
......@@ -1396,7 +1398,7 @@ fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOpti
13961398 }
13971399 }
13981400
1399 try formatInt(ns_remaining, 10, false, .{}, writer);
1401 try formatInt(ns_remaining, 10, .lower, .{}, writer);
14001402 try writer.writeAll("ns");
14011403 return;
14021404}
......@@ -1673,10 +1675,10 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
16731675 return value;
16741676}
16751677
1676pub fn digitToChar(digit: u8, uppercase: bool) u8 {
1678pub fn digitToChar(digit: u8, case: Case) u8 {
16771679 return switch (digit) {
16781680 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),
16801682 else => unreachable,
16811683 };
16821684}
......@@ -1728,25 +1730,25 @@ test "bufPrintInt" {
17281730 var buffer: [100]u8 = undefined;
17291731 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{}));
1734 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, false, FormatOptions{}));
1735 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, false, FormatOptions{}));
1736 try std.testing.expectEqualSlices(u8, "-BC614E", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, true, FormatOptions{}));
1735 try std.testing.expectEqualSlices(u8, "-101111000110000101001110", bufPrintIntToSlice(buf, @as(i32, -12345678), 2, .lower, FormatOptions{}));
1736 try std.testing.expectEqualSlices(u8, "-12345678", bufPrintIntToSlice(buf, @as(i32, -12345678), 10, .lower, FormatOptions{}));
1737 try std.testing.expectEqualSlices(u8, "-bc614e", bufPrintIntToSlice(buf, @as(i32, -12345678), 16, .lower, 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 }));
1741 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 6 }));
1742 try std.testing.expectEqualSlices(u8, "1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, false, FormatOptions{ .width = 1 }));
1742 try std.testing.expectEqualSlices(u8, " 666", bufPrintIntToSlice(buf, @as(u32, 666), 10, .lower, FormatOptions{ .width = 6 }));
1743 try std.testing.expectEqualSlices(u8, " 1234", bufPrintIntToSlice(buf, @as(u32, 0x1234), 16, .lower, FormatOptions{ .width = 6 }));
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 }));
1745 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 }));
1747 try std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, .lower, FormatOptions{ .width = 3 }));
17461748}
17471749
1748pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
1749 return buf[0..formatIntBuf(buf, value, base, uppercase, options)];
1750pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) []u8 {
1751 return buf[0..formatIntBuf(buf, value, base, case, options)];
17501752}
17511753
17521754pub 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 {
11401140 out_stream: anytype,
11411141 ) !void {
11421142 comptime var radix = 10;
1143 comptime var uppercase = false;
1143 comptime var case: std.fmt.Case = .lower;
11441144
11451145 if (fmt.len == 0 or comptime mem.eql(u8, fmt, "d")) {
11461146 radix = 10;
1147 uppercase = false;
1147 case = .lower;
11481148 } else if (comptime mem.eql(u8, fmt, "b")) {
11491149 radix = 2;
1150 uppercase = false;
1150 case = .lower;
11511151 } else if (comptime mem.eql(u8, fmt, "x")) {
11521152 radix = 16;
1153 uppercase = false;
1153 case = .lower;
11541154 } else if (comptime mem.eql(u8, fmt, "X")) {
11551155 radix = 16;
1156 uppercase = true;
1156 case = .upper;
11571157 } else {
11581158 @compileError("Unknown format string: '" ++ fmt ++ "'");
11591159 }
......@@ -1171,7 +1171,7 @@ pub const Const = struct {
11711171 .positive = false,
11721172 };
11731173 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);
11751175 return out_stream.writeAll(buf[0..len]);
11761176 }
11771177
......@@ -1179,7 +1179,7 @@ pub const Const = struct {
11791179 /// Caller owns returned memory.
11801180 /// Asserts that `base` is in the range [2, 16].
11811181 /// 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 {
11831183 assert(base >= 2);
11841184 assert(base <= 16);
11851185
......@@ -1192,7 +1192,7 @@ pub const Const = struct {
11921192 const limbs = try allocator.alloc(Limb, calcToStringLimbsBufferLen(self.limbs.len, base));
11931193 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));
11961196 }
11971197
11981198 /// Converts self to a string in the requested base.
......@@ -1204,7 +1204,7 @@ pub const Const = struct {
12041204 /// length of at least `calcToStringLimbsBufferLen`.
12051205 /// In the case of power-of-two base, `limbs_buffer` is ignored.
12061206 /// 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 {
12081208 assert(base >= 2);
12091209 assert(base <= 16);
12101210
......@@ -1223,7 +1223,7 @@ pub const Const = struct {
12231223 var shift: usize = 0;
12241224 while (shift < limb_bits) : (shift += base_shift) {
12251225 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);
12271227 string[digits_len] = ch;
12281228 digits_len += 1;
12291229 // If we hit the end, it must be all zeroes from here.
......@@ -1269,7 +1269,7 @@ pub const Const = struct {
12691269 var r_word = r.limbs[0];
12701270 var i: usize = 0;
12711271 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);
12731273 r_word /= base;
12741274 string[digits_len] = ch;
12751275 digits_len += 1;
......@@ -1281,7 +1281,7 @@ pub const Const = struct {
12811281
12821282 var r_word = q.limbs[0];
12831283 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);
12851285 r_word /= base;
12861286 string[digits_len] = ch;
12871287 digits_len += 1;
......@@ -1615,9 +1615,9 @@ pub const Managed = struct {
16151615
16161616 /// Converts self to a string in the requested base. Memory is allocated from the provided
16171617 /// 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 {
16191619 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);
16211621 }
16221622
16231623 /// 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" {
277277 var a = try Managed.initSet(testing.allocator, 120317241209124781241290847124);
278278 defer a.deinit();
279279
280 const as = try a.toString(testing.allocator, 10, false);
280 const as = try a.toString(testing.allocator, 10, .lower);
281281 defer testing.allocator.free(as);
282282 const es = "120317241209124781241290847124";
283283
......@@ -288,14 +288,14 @@ test "big.int string to base base error" {
288288 var a = try Managed.initSet(testing.allocator, 0xffffffff);
289289 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));
292292}
293293
294294test "big.int string to base 2" {
295295 var a = try Managed.initSet(testing.allocator, -0b1011);
296296 defer a.deinit();
297297
298 const as = try a.toString(testing.allocator, 2, false);
298 const as = try a.toString(testing.allocator, 2, .lower);
299299 defer testing.allocator.free(as);
300300 const es = "-1011";
301301
......@@ -306,7 +306,7 @@ test "big.int string to base 16" {
306306 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
307307 defer a.deinit();
308308
309 const as = try a.toString(testing.allocator, 16, false);
309 const as = try a.toString(testing.allocator, 16, .lower);
310310 defer testing.allocator.free(as);
311311 const es = "efffffff00000001eeeeeeefaaaaaaab";
312312
......@@ -317,7 +317,7 @@ test "big.int neg string to" {
317317 var a = try Managed.initSet(testing.allocator, -123907434);
318318 defer a.deinit();
319319
320 const as = try a.toString(testing.allocator, 10, false);
320 const as = try a.toString(testing.allocator, 10, .lower);
321321 defer testing.allocator.free(as);
322322 const es = "-123907434";
323323
......@@ -328,7 +328,7 @@ test "big.int zero string to" {
328328 var a = try Managed.initSet(testing.allocator, 0);
329329 defer a.deinit();
330330
331 const as = try a.toString(testing.allocator, 10, false);
331 const as = try a.toString(testing.allocator, 10, .lower);
332332 defer testing.allocator.free(as);
333333 const es = "0";
334334
......@@ -1180,7 +1180,7 @@ test "big.int div multi-multi zero-limb trailing (with rem)" {
11801180
11811181 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);
11841184 defer testing.allocator.free(rs);
11851185 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
11861186}
......@@ -1199,7 +1199,7 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
11991199
12001200 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);
12031203 defer testing.allocator.free(rs);
12041204 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
12051205}
......@@ -1216,11 +1216,11 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li
12161216 defer r.deinit();
12171217 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);
12201220 defer testing.allocator.free(qs);
12211221 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);
12241224 defer testing.allocator.free(rs);
12251225 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
12261226}
......@@ -1240,11 +1240,11 @@ test "big.int div multi-multi fuzz case #1" {
12401240 defer r.deinit();
12411241 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);
12441244 defer testing.allocator.free(qs);
12451245 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);
12481248 defer testing.allocator.free(rs);
12491249 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
12501250}
......@@ -1264,11 +1264,11 @@ test "big.int div multi-multi fuzz case #2" {
12641264 defer r.deinit();
12651265 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);
12681268 defer testing.allocator.free(qs);
12691269 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);
12721272 defer testing.allocator.free(rs);
12731273 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
12741274}
......@@ -1533,7 +1533,7 @@ test "big.int pow" {
15331533
15341534 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);
15371537 defer testing.allocator.free(ys);
15381538 try testing.expectEqualSlices(
15391539 u8,
lib/std/zig/fmt.zig+1-1
......@@ -68,7 +68,7 @@ pub fn formatEscapes(
6868 // Use hex escapes for rest any unprintable characters.
6969 else => {
7070 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);
7272 },
7373 };
7474}
src/Compilation.zig+1-1
......@@ -4009,7 +4009,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
40094009 });
40104010 var digest_plus_flags: [digest.len + 2]u8 = undefined;
40114011 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, .{
40134013 .width = 2,
40144014 .fill = '0',
40154015 }) == 2);
src/DepTokenizer.zig+2-2
......@@ -1026,13 +1026,13 @@ fn hexDump16(out: anytype, offset: usize, bytes: []const u8) !void {
10261026
10271027fn printDecValue(out: anytype, value: u64, width: u8) !void {
10281028 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' });
10301030 try out.writeAll(buffer[0..len]);
10311031}
10321032
10331033fn printHexValue(out: anytype, value: u64, width: u8) !void {
10341034 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' });
10361036 try out.writeAll(buffer[0..len]);
10371037}
10381038
src/Zir.zig+1-1
......@@ -3231,7 +3231,7 @@ const Writer = struct {
32313231 .limbs = limbs,
32323232 .positive = true,
32333233 };
3234 const as_string = try big_int.toStringAlloc(self.gpa, 10, false);
3234 const as_string = try big_int.toStringAlloc(self.gpa, 10, .lower);
32353235 defer self.gpa.free(as_string);
32363236 try stream.print("{s})", .{as_string});
32373237 }
src/translate_c.zig+4-4
......@@ -4146,7 +4146,7 @@ fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !Node {
41464146 }
41474147
41484148 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) {
41504150 error.OutOfMemory => return error.OutOfMemory,
41514151 };
41524152 const res = try Tag.integer_literal.create(c.arena, str);
......@@ -5083,7 +5083,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
50835083 num += c - 'A' + 10;
50845084 },
50855085 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 });
50875087 num = 0;
50885088 if (c == '\\')
50895089 state = .Escape
......@@ -5109,7 +5109,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
51095109 };
51105110 num += c - '0';
51115111 } 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 });
51135113 num = 0;
51145114 count = 0;
51155115 if (c == '\\')
......@@ -5123,7 +5123,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
51235123 }
51245124 }
51255125 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 });
51275127 return bytes[0..i];
51285128}
51295129
test/behavior/enum_with_members.zig+2-2
......@@ -8,8 +8,8 @@ const ET = union(enum) {
88
99 pub fn print(a: *const ET, buf: []u8) anyerror!usize {
1010 return switch (a.*) {
11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, fmt.FormatOptions{}),
12 ET.UINT => |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, .lower, fmt.FormatOptions{}),
1313 };
1414 }
1515};