Skip to content

std.fmt: Add {q} format specifier #6756

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

Closed
Tetralux opened this issue Oct 21, 2020 · 4 comments
Closed

std.fmt: Add {q} format specifier #6756

Tetralux opened this issue Oct 21, 2020 · 4 comments
Labels
standard library This issue involves writing Zig code for the standard library.

Comments

@Tetralux
Copy link
Contributor

q meaning "quoted", handy for printf-debugging; especially where \rs are involved.
Generally useful when writing string manipulation code.

var s: []const u8 = "hello\x00world\r\n";
std.debug.warn("Content: {q}\n", .{s});
// Content: "hello\x00world\r\n"
@ikskuh
Copy link
Contributor

ikskuh commented Oct 21, 2020

Sadly, this is only trivial for ASCII characters. There might be unicode spaces that should be escaped in such a string, especially stuff like U+200B (zero width space). Or we can ignore this and just display the control characters (< 0x20, 0x7F)

@LemonBoy
Copy link
Contributor

According to #1358 we could use the ? specifier instead of minting a new one.

Or we can ignore this and just display the control characters (< 0x20, 0x7F)

👍

@daurnimator
Copy link
Contributor

Practically a dupe of #6218

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Oct 21, 2020
@andrewrk
Copy link
Member

Practically a dupe of #6218

Yes this looks like a dupe of #6218.

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

No branches or pull requests

5 participants