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; } pub fn literal(w: *std.Io.Writer, host: []const u8) !void { const bare = std.mem.trim(u8, host, "[]"); if (std.mem.indexOfScalar(u8, bare, ':') != null) try w.print("[IPv6:{s}]", .{bare}) else try w.print("[{s}]", .{bare}); }