authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-19 19:02:30+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-02 17:12:57-07:00
log5a06fdfa5525920810005e73eaa1b6e79a6472ca
treec09a368bb45340ca8b174bfb6eef673ca4d0fc0c
parentd4a8fc8b67bd2ae26b997ee201545cbb1eb3c15f

Use same brace pairs for arrays/slices/vectors


1 files changed, 9 insertions(+), 9 deletions(-)

lib/std/fmt.zig+9-9
......@@ -518,7 +518,7 @@ pub fn formatType(
518518 return formatType(mem.span(value), fmt, options, writer, max_depth);
519519 }
520520 if (ptr_info.child == u8) {
521 if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
521 if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
522522 return formatText(mem.span(value), fmt, options, writer);
523523 }
524524 }
......@@ -526,21 +526,21 @@ pub fn formatType(
526526 },
527527 .Slice => {
528528 if (max_depth == 0) {
529 return writer.writeAll("[ ... ]");
529 return writer.writeAll("{ ... }");
530530 }
531531 if (ptr_info.child == u8) {
532 if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
532 if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
533533 return formatText(value, fmt, options, writer);
534534 }
535535 }
536 try writer.writeAll("[");
536 try writer.writeAll("{ ");
537537 for (value) |elem, i| {
538538 try formatType(elem, fmt, options, writer, max_depth);
539539 if (i != value.len - 1) {
540540 try writer.writeAll(", ");
541541 }
542542 }
543 try writer.writeAll("]");
543 try writer.writeAll(" }");
544544 },
545545 },
546546 .Array => |info| {
......@@ -1593,10 +1593,10 @@ test "slice" {
15931593 {
15941594 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
15951595 var runtime_zero: usize = 0;
1596 try testFmt("int: [1, 4096, 391891, 1111111111]", "int: {}", .{int_slice[runtime_zero..]});
1597 try testFmt("int: [1, 4096, 391891, 1111111111]", "int: {d}", .{int_slice[runtime_zero..]});
1598 try testFmt("int: [1, 1000, 5fad3, 423a35c7]", "int: {x}", .{int_slice[runtime_zero..]});
1599 try testFmt("int: [00001, 01000, 5fad3, 423a35c7]", "int: {x:0>5}", .{int_slice[runtime_zero..]});
1596 try testFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {}", .{int_slice[runtime_zero..]});
1597 try testFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});
1598 try testFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});
1599 try testFmt("int: { 00001, 01000, 5fad3, 423a35c7 }", "int: {x:0>5}", .{int_slice[runtime_zero..]});
16001600 }
16011601}
16021602