module Lambdabot.Nick
( Nick(..)
, fmtNick
, parseNick
) where
import Lambdabot.Util
import Data.Char
data Nick = Nick
{ nTag :: !String
, nName :: !String
}
canonicalizeName :: String -> String
canonicalizeName = strip isSpace . map toUpper
instance Eq Nick where
(Nick tag name) == (Nick tag2 name2) =
(canonicalizeName name == canonicalizeName name2) && (tag == tag2)
instance Ord Nick where
(Nick tag name) <= (Nick tag2 name2) =
(tag, canonicalizeName name) <= (tag2, canonicalizeName name2)
fmtNick :: String -> Nick -> String
fmtNick svr nck
| nTag nck == svr = nName nck
| otherwise = nTag nck ++ ':' : nName nck
parseNick :: String -> String -> Nick
parseNick def str
| null ac = Nick def str
| otherwise = Nick bc ac
where
(bc, ac') = break (==':') str
ac = drop 1 ac'