module Network.FastIRC.Utils
(
isCommandChar,
isHostChar,
isIRCEOLChar,
isIRCTokChar,
isMessageChar,
isNickChar,
isServerChar,
isUserChar,
parseComplete
)
where
import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.Char8
isCommandChar :: Char -> Bool
isCommandChar = inClass "A-Za-z0-9_"
isIRCTokChar :: Char -> Bool
isIRCTokChar c = c /= ' ' && c /= '\r' && c /= '\n'
isIRCEOLChar :: Char -> Bool
isIRCEOLChar c = c == '\n' || c == '\r'
isMessageChar :: Char -> Bool
isMessageChar c = c /= '\n' && c /= '\r'
isUserSpecChar :: Char -> Bool
isUserSpecChar c = c > '!' && c /= '@'
isNickChar :: Char -> Bool
isNickChar = isUserSpecChar
isUserChar :: Char -> Bool
isUserChar = isUserSpecChar
isHostChar :: Char -> Bool
isHostChar = isUserSpecChar
isServerChar :: Char -> Bool
isServerChar c = inClass "a-zA-Z0-9.:-" c || c >= '\x80'
parseComplete :: Parser a -> B.ByteString -> Maybe a
parseComplete p = complete . parse p
where
complete :: Result a -> Maybe a
complete (Partial f) = complete (f B.empty)
complete (Done _ r) = Just r
complete (Fail _ _ _) = Nothing