-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pretty print Slices #6680
Pretty print Slices #6680
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -456,6 +456,18 @@ pub fn formatType( | |||||
} | ||||||
if (ptr_info.child == u8) { | ||||||
return formatText(value, fmt, options, writer); | ||||||
} else if (fmt.len > 0 and ((fmt[0] == 'v') or (fmt[0] == 'V'))) { | ||||||
try format(writer, "[", .{}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're not formatting anything then |
||||||
var i: usize = 0; | ||||||
for (value) |one| { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need to evaluate the |
||||||
if (i == value.len - 1) { | ||||||
try format(writer, "{}", .{one}); | ||||||
} else { | ||||||
try format(writer, "{}, ", .{one}); | ||||||
} | ||||||
i += 1; | ||||||
} | ||||||
return format(writer, "]", .{}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||||||
} | ||||||
return format(writer, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); | ||||||
}, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v
for vendetta? Why bother with two format specifiers when you're treating them the same way?This way you can't specify what format to use for the content, I'd accept two-char formats too (eg.
xv
orvx
to print the slice contents as hex).Maybe this is better suited for the
*
specifier, that's supposed to deref the input.