Skip to content

Commit

Permalink
Use same brace pairs for arrays/slices/vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonBoy authored and andrewrk committed Jan 3, 2021
1 parent d4a8fc8 commit 5a06fdf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/std/fmt.zig
Expand Up @@ -518,29 +518,29 @@ pub fn formatType(
return formatType(mem.span(value), fmt, options, writer, max_depth);
}
if (ptr_info.child == u8) {
if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
if (fmt.len > 0 and comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
return formatText(mem.span(value), fmt, options, writer);
}
}
return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value) });
},
.Slice => {
if (max_depth == 0) {
return writer.writeAll("[ ... ]");
return writer.writeAll("{ ... }");
}
if (ptr_info.child == u8) {
if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXzZ", fmt[0]) != null) {
if (fmt.len == 0 or comptime mem.indexOfScalar(u8, "sxXeEzZ", fmt[0]) != null) {
return formatText(value, fmt, options, writer);
}
}
try writer.writeAll("[");
try writer.writeAll("{ ");
for (value) |elem, i| {
try formatType(elem, fmt, options, writer, max_depth);
if (i != value.len - 1) {
try writer.writeAll(", ");
}
}
try writer.writeAll("]");
try writer.writeAll(" }");
},
},
.Array => |info| {
Expand Down Expand Up @@ -1593,10 +1593,10 @@ test "slice" {
{
var int_slice = [_]u32{ 1, 4096, 391891, 1111111111 };
var runtime_zero: usize = 0;
try testFmt("int: [1, 4096, 391891, 1111111111]", "int: {}", .{int_slice[runtime_zero..]});
try testFmt("int: [1, 4096, 391891, 1111111111]", "int: {d}", .{int_slice[runtime_zero..]});
try testFmt("int: [1, 1000, 5fad3, 423a35c7]", "int: {x}", .{int_slice[runtime_zero..]});
try testFmt("int: [00001, 01000, 5fad3, 423a35c7]", "int: {x:0>5}", .{int_slice[runtime_zero..]});
try testFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {}", .{int_slice[runtime_zero..]});
try testFmt("int: { 1, 4096, 391891, 1111111111 }", "int: {d}", .{int_slice[runtime_zero..]});
try testFmt("int: { 1, 1000, 5fad3, 423a35c7 }", "int: {x}", .{int_slice[runtime_zero..]});
try testFmt("int: { 00001, 01000, 5fad3, 423a35c7 }", "int: {x:0>5}", .{int_slice[runtime_zero..]});
}
}

Expand Down

0 comments on commit 5a06fdf

Please sign in to comment.