From 3dbac838d6bf37842a478d47e8fbdd15cddbde7a Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 29 May 2023 13:18:58 -0700 Subject: [PATCH] support printing [N]u8 --- src/lib.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.zig b/src/lib.zig index cd9d1a6056ceb47b144920e7ded9763f091c172b..bd218cfd86db59dcf41d2368e555521abb8e62b2 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -113,6 +113,15 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V try writer.writeAll(try x.toString(alloc)); return; } + if (comptime isArrayOf(u8)(TO)) { + if (repl.raw) { + try writer.writeAll(&x); + return; + } + const s = std.mem.trim(u8, &x, "\n"); + try writeEscaped(s, writer); + return; + } @compileError(std.fmt.comptimePrint("pek: print {s}: unsupported type: {s}", .{ v, @typeName(TO) })); }, .block => |v| { @@ -356,3 +365,15 @@ fn docap(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value, try do(alloc, writer, bottom, data, ctx, opts); } } + +fn isArrayOf(comptime T: type) std.meta.trait.TraitFn { + const Closure = struct { + pub fn trait(comptime C: type) bool { + return switch (@typeInfo(C)) { + .Array => |ti| ti.child == T, + else => false, + }; + } + }; + return Closure.trait; +} -- 2.54.0