diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-20 18:57:33 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2026-10-20 18:57:33 -0500 |
| commit | ad821a3e2cfb535c62ac2041c951433b6e99db58 (patch) | |
| tree | c48f939a28be8ffe4f1ab3f291c7510dfe606ab4 /src/bin/util.zig | |
| parent | 735cb3fedd5f8adf89cfc869103e4e7992a61139 (diff) | |
| download | nvlope-ad821a3e2cfb535c62ac2041c951433b6e99db58.tar.gz | |
Spool in progress
Diffstat (limited to 'src/bin/util.zig')
| -rw-r--r-- | src/bin/util.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/bin/util.zig b/src/bin/util.zig new file mode 100644 index 0000000..756ed74 --- /dev/null +++ b/src/bin/util.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +pub fn validateUser(user: []const u8) !void { + if (user.len == 0 or user.len > 64) return error.InvalidUser; + if (user[0] == '.') return error.InvalidUser; + for (user) |c| switch (c) { + 'a'...'z', '0'...'9', '.', '_', '-' => {}, + else => return error.InvalidUser, + }; +} + +pub fn normalizeUser(user: []const u8, buf: *[64]u8) ![]const u8 { + const out = std.ascii.lowerString(buf, user); + try validateUser(out); + return out; +} |
