Skip to content

std: add fmt option to escape non-printable characters #6218

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

Merged
merged 1 commit into from
Sep 2, 2020

Conversation

daurnimator
Copy link
Contributor

No description provided.

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Aug 31, 2020
@data-man

This comment has been minimized.

@@ -599,6 +600,16 @@ pub fn formatText(
try formatInt(c, 16, fmt[0] == 'X', FormatOptions{ .width = 2, .fill = '0' }, writer);
}
return;
} else if (comptime (std.mem.eql(u8, fmt, "e") or std.mem.eql(u8, fmt, "E"))) {
for (bytes) |c| {
if (std.ascii.isPrint(c)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we consider \t, \n and \r printable? (#4014)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For purposes of a debug print: I don't think they should be considered printable:

  • its hard to visually tell the difference between a tab that is one space wide an a normal space character.
  • I imagine this would often be used for line based output, where escaping newlines is desired.
  • \r is unprintable

@andrewrk andrewrk merged commit fb3c5b8 into ziglang:master Sep 2, 2020
@daurnimator daurnimator deleted the fmt-non-printable branch September 3, 2020 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants