From cd86e774d55da804a1ce17c2b0cb98bf9be6b01d Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Thu, 28 Nov 2024 17:57:29 +0200 Subject: [PATCH] Like `niceTypeName` to its own file of utils --- src/args/utils.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/args/utils.zig diff --git a/src/args/utils.zig b/src/args/utils.zig new file mode 100644 index 0000000..75d482b --- /dev/null +++ b/src/args/utils.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +pub fn niceTypeName(comptime T: type) []const u8 { + if (T == []const u8) { + return "string"; + } + + const name = @typeName(T); + + if (std.mem.startsWith(u8, name, "array_list.ArrayListAligned")) { + return "array"; + } + + return name; +} + +const t = std.testing; + +test "nice type names" { + try t.expectEqualStrings("string", niceTypeName([]const u8)); + try t.expectEqualStrings("array", niceTypeName(std.ArrayList(u8))); + + try t.expectEqualStrings("u8", niceTypeName(u8)); +}