authorgravatar for 37453713+ominitay@users.noreply.github.comominitay <37453713+ominitay@users.noreply.github.com> 2022-07-31 22:58:04+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-02-01 21:43:36+02:00
log3c8d9681946630a1d953cb2c37cad248c7445093
tree6e7f10a8c6dd8e942e76e9a5a1d39fb4361eab28
parent2ccff5115454bab4898bae3de88f5619310bc5c1

fmt: Make default_max_depth configurable


2 files changed, 11 insertions(+), 5 deletions(-)

lib/std/fmt.zig+6-5
......@@ -1,11 +1,12 @@
11const std = @import("std.zig");
2const builtin = @import("builtin");
3
24const io = std.io;
35const math = std.math;
46const assert = std.debug.assert;
57const mem = std.mem;
68const unicode = std.unicode;
79const meta = std.meta;
8const builtin = @import("builtin");
910const errol = @import("fmt/errol.zig");
1011const lossyCast = std.math.lossyCast;
1112const expectFmt = std.testing.expectFmt;
......@@ -190,7 +191,7 @@ pub fn format(
190191 .precision = precision,
191192 },
192193 writer,
193 default_max_depth,
194 std.options.fmt_max_depth,
194195 );
195196 }
196197
......@@ -2140,15 +2141,15 @@ test "buffer" {
21402141 {
21412142 var buf1: [32]u8 = undefined;
21422143 var fbs = std.io.fixedBufferStream(&buf1);
2143 try formatType(1234, "", FormatOptions{}, fbs.writer(), default_max_depth);
2144 try formatType(1234, "", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
21442145 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234"));
21452146
21462147 fbs.reset();
2147 try formatType('a', "c", FormatOptions{}, fbs.writer(), default_max_depth);
2148 try formatType('a', "c", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
21482149 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "a"));
21492150
21502151 fbs.reset();
2151 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), default_max_depth);
2152 try formatType(0b1100, "b", FormatOptions{}, fbs.writer(), std.options.fmt_max_depth);
21522153 try std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100"));
21532154 }
21542155}
lib/std/std.zig+5
......@@ -153,6 +153,11 @@ pub const options = struct {
153153 else
154154 log.defaultLog;
155155
156 pub const fmt_max_depth = if (@hasDecl(options_override, "fmt_max_depth"))
157 options_override.fmt_max_depth
158 else
159 fmt.default_max_depth;
160
156161 pub const cryptoRandomSeed: fn (buffer: []u8) void = if (@hasDecl(options_override, "cryptoRandomSeed"))
157162 options_override.cryptoRandomSeed
158163 else