{- This file is part of irc-fun-messages. - - Written in 2015 by fr33domlover . - - ♡ Copying is an act of love. Please copy, reuse and share. - - The author(s) have dedicated all copyright and related and neighboring - rights to this software to the public domain worldwide. This software is - distributed without any warranty. - - You should have received a copy of the CC0 Public Domain Dedication along - with this software. If not, see - . -} module Network.Irc.Messages.Internal.Tokens.Other ( user , key , letter , digit , hexdigit , hexdigit' , special ) where import Data.Char (isAscii, isDigit) import Data.Text (pack) import Network.Irc.Messages.Internal.Types import Network.Irc.Types import Text.Regex.Applicative user :: Regex Username user = Username . pack <$> some (psym (`notElem` "\0\r\n @")) key :: Regex ChannelKey key = ChannelKey . pack <$> some (psym $ \ c -> isAscii c && c `notElem` "\0\r\n\f\t\v ") letter :: Regex Char letter = psym $ \ c -> 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' digit :: Regex Char digit = psym isDigit hexdigit :: Regex Char hexdigit = digit <|> upperhex where upperhex = psym $ \ c -> 'A' <= c && c <= 'F' -- RFC 2812 assumes IPv6 addresses with uppercase hex digits. In practice, the -- recommendation it to use lowercase, and that's what really happens. So this -- regex accepts both lowercase and uppercase. hexdigit' :: Regex Char hexdigit' = digit <|> upperhex <|> lowerhex where upperhex = psym $ \ c -> 'A' <= c && c <= 'F' lowerhex = psym $ \ c -> 'a' <= c && c <= 'f' special :: Regex Char special = psym (`elem` "[]\\`_^{|}")