-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
21bc335 changed the behavior of the {c} formatting directive:
- return output(context, @as(*const [1]u8, &c)[0..]);
+ if (std.ascii.isPrint(c))
+ return output(context, @as(*const [1]u8, &c)[0..]);
+ return format(context, Errors, output, "\\x{x:0<2}", .{c});The effect of this is:
fn printChars(s: []const u8) void {
for (s) |c| {
std.debug.warn("{c}", .{c});
}
}
// old behavior:
// printChars("foo\tbar") -> foo bar
// new behavior:
// printChars("foo\tbar") -> foo\x09barThis is because std.ascii.isPrint returns false on whitespace other than 0x20 ( ).
This behavior does not match the behavior of the %c directive in C, Go, and other languages. Is this departure intentional? If so, what's the proper way to print a string character-by-character?
Metadata
Metadata
Assignees
Labels
standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.