talircd/lib/irc/types.ml

27 lines
578 B
OCaml
Raw Normal View History

2024-01-10 01:20:39 +00:00
type name = string
type userinfo = {
username : string;
realname : string;
hostname : string;
}
let pp_userinfo ppf { username; realname; hostname } =
ignore realname;
Format.fprintf ppf "!%s@%s" username hostname
2024-01-10 01:20:39 +00:00
let name_type s =
let rec valid i =
if i >= String.length s then true
else
match s.[i] with
| ' ' | '@' | '+' | ',' -> false
| _ -> valid (i + 1)
in
if s = "" then `invalid
else
match s.[0] with
| ':' -> `invalid
| '#' -> if valid 1 then `chan else `invalid
| _ -> if valid 0 then `nick else `invalid