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(...@@ -518,7 +518,7 @@ pub fn formatType(
518 return formatType(mem.span(value), fmt, options, writer, max_depth);518 return formatType(mem.span(value), fmt, options, writer, max_depth);
519 }519 }
520 if (ptr_info.child == u8) {520 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) {
522 return formatText(mem.span(value), fmt, options, writer);522 return formatText(mem.span(value), fmt, options, writer);
523 }523 }
524 }524 }
...@@ -526,21 +526,21 @@ pub fn formatType(...@@ -526,21 +526,21 @@ pub fn formatType(
526 },526 },
527 .Slice => {527 .Slice => {
528 if (max_depth == 0) {528 if (max_depth == 0) {
529 return writer.writeAll("[ ... ]");529 return writer.writeAll("{ ... }");
530 }530 }
531 if (ptr_info.child == u8) {531 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) {
533 return formatText(value, fmt, options, writer);533 return formatText(value, fmt, options, writer);
534 }534 }
535 }535 }
536 try writer.writeAll("[");536 try writer.writeAll("{ ");
537 for (value) |elem, i| {537 for (value) |elem, i| {
538 try formatType(elem, fmt, options, writer, max_depth);538 try formatType(elem, fmt, options, writer, max_depth);
539 if (i != value.len - 1) {539 if (i != value.len - 1) {
540 try writer.writeAll(", ");540 try writer.writeAll(", ");
541 }541 }
542 }542 }
543 try writer.writeAll("]");543 try writer.writeAll(" }");
544 },544 },
545 },545 },
546 .Array => |info| {546 .Array => |info| {
...@@ -1593,10 +1593,10 @@ test "slice" {...@@ -1593,10 +1593,10 @@ test "slice" {
1593 {1593 {
1594 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };1594 var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
1595 var runtime_zero: usize = 0;1595 var runtime_zero: usize = 0;
1596 try testFmt("int: [1, 4096, 391891, 1111111111]", "int: {}", .{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..]});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..]});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..]});1599 try testFmt("int: { 00001, 01000, 5fad3, 423a35c7 }", "int: {x:0>5}", .{int_slice[runtime_zero..]});
1600 }1600 }
1601}1601}
16021602