authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-15 23:08:02+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-16 12:17:16-05:00
log7e5e767ba0fdde91dd66690168eff96b75c28e33
treea61f996ad83f99369b7273e50b8221f1b99ba2e4
parent0267afa9c0aac51089150a9d2f6b2e53e9d2dbff

Fix regression in char printing

Closes #4014

2 files changed, 9 insertions(+), 4 deletions(-)

lib/std/fmt.zig+1-3
...@@ -585,9 +585,7 @@ pub fn formatAsciiChar(...@@ -585,9 +585,7 @@ pub fn formatAsciiChar(
585 comptime Errors: type,585 comptime Errors: type,
586 output: fn (@TypeOf(context), []const u8) Errors!void,586 output: fn (@TypeOf(context), []const u8) Errors!void,
587) Errors!void {587) Errors!void {
588 if (std.ascii.isPrint(c))588 return output(context, @as(*const [1]u8, &c)[0..]);
589 return output(context, @as(*const [1]u8, &c)[0..]);
590 return format(context, Errors, output, "\\x{x:0<2}", .{c});
591}589}
592590
593pub fn formatBuf(591pub fn formatBuf(
src-self-hosted/translate_c.zig+8-1
...@@ -1708,7 +1708,14 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {...@@ -1708,7 +1708,14 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 {
1708 '\n' => "\\n"[0..],1708 '\n' => "\\n"[0..],
1709 '\r' => "\\r"[0..],1709 '\r' => "\\r"[0..],
1710 '\t' => "\\t"[0..],1710 '\t' => "\\t"[0..],
1711 else => std.fmt.bufPrint(char_buf[0..], "{c}", .{c}) catch unreachable,1711 else => {
1712 // Handle the remaining escapes Zig doesn't support by turning them
1713 // into their respective hex representation
1714 if (std.ascii.isCntrl(c))
1715 return std.fmt.bufPrint(char_buf[0..], "\\x{x:0<2}", .{c}) catch unreachable
1716 else
1717 return std.fmt.bufPrint(char_buf[0..], "{c}", .{c}) catch unreachable;
1718 },
1712 };1719 };
1713}1720}
17141721