blob: 756ed7400f2c50b4b4f1f273404b728a2d9a6583 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}
|