| author | |
| committer | |
| log | 1d97747665b993eb0c625c8d0a28e2d0c8e167a3 |
| tree | 39704246d55eb124bf02b80a7df696f962bce22c |
| parent | db1e97d4b19d8399252e0fbc85fc3563b005a892 |
This code is adapted from pixelherodev paste from IRC
I have added a new fmt option to handle printing slice values ``{v}`` or ``{V}``
While i think it can be made the default, i want your opinion about it
```zig
var slicea = [0]u32{};
var sliceb = [3]u32{ 1, 2, 3 };
std.log.info("Content: {v}", .{slicea});
std.log.info("Content: {v}", .{sliceb});
```
will print:
```
info: Content: []
info: Content: [1, 2, 3]
```
Question:
Should we drop ``{v}`` and make it the default behavior?1 files changed, 12 insertions(+), 0 deletions(-)
lib/std/fmt.zig+12| ... | ... | @@ -504,6 +504,18 @@ pub fn formatType( |
| 504 | 504 | } |
| 505 | 505 | if (ptr_info.child == u8) { |
| 506 | 506 | return formatText(value, fmt, options, writer); |
| 507 | } else if (fmt.len > 0 and ((fmt[0] == 'v') or (fmt[0] == 'V'))) { | |
| 508 | try format(writer, "[", .{}); | |
| 509 | var i: usize = 0; | |
| 510 | for (value) |one| { | |
| 511 | if (i == value.len - 1) { | |
| 512 | try format(writer, "{}", .{one}); | |
| 513 | } else{ | |
| 514 | try format(writer, "{}, ", .{one}); | |
| 515 | } | |
| 516 | i += 1; | |
| 517 | } | |
| 518 | return format(writer, "]", .{}); | |
| 507 | 519 | } |
| 508 | 520 | return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); |
| 509 | 521 | }, |