    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Data.CharSet.Posix.Ascii
    -- Copyright   :  (c) Edward Kmett 2010
    -- License     :  BSD3
    -- Maintainer  :  ekmett@gmail.com
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -------------------------------------------------------------------------------

    module Data.CharSet.Posix.Ascii
        ( posixAscii
        , lookupPosixAsciiCharSet
        -- * Traditional POSIX ASCII \"classes\"
        , alnum, alpha, ascii, blank, cntrl, digit, graph, print, word, punct, space, upper, lower, xdigit
        ) where

    import Prelude hiding (print)
    import Data.Char
    import Data.CharSet
    import Data.HashMap.Lazy (HashMap)
    import qualified Data.HashMap.Lazy as HashMap

    alnum, alpha, ascii, blank, cntrl, digit, graph, print, word, punct, space, upper, lower, xdigit :: CharSet
    alnum :: CharSet
    alnum = CharSet
    alpha CharSet -> CharSet -> CharSet
    `union` CharSet
    digit
    alpha :: CharSet
    alpha = CharSet
    lower CharSet -> CharSet -> CharSet
    `union` CharSet
    upper
    ascii :: CharSet
    ascii = Char -> Char -> CharSet
    range '\x00' '\x7f'
    blank :: CharSet
    blank = String -> CharSet
    fromList " \t"
    cntrl :: CharSet
    cntrl = Char -> CharSet -> CharSet
    insert '\x7f' (CharSet -> CharSet) -> CharSet -> CharSet
    forall a b. (a -> b) -> a -> b
    $ Char -> Char -> CharSet
    range '\x00' '\x1f'
    digit :: CharSet
    digit = Char -> Char -> CharSet
    range '0' '9'
    lower :: CharSet
    lower = Char -> Char -> CharSet
    range 'a' 'z'
    upper :: CharSet
    upper = Char -> Char -> CharSet
    range 'A' 'Z'
    graph :: CharSet
    graph = Char -> Char -> CharSet
    range '\x21' '\x7e'
    print :: CharSet
    print = Char -> CharSet -> CharSet
    insert '\x20' CharSet
    graph
    word :: CharSet
    word  = Char -> CharSet -> CharSet
    insert '_' CharSet
    alnum
    punct :: CharSet
    punct = String -> CharSet
    fromList "-!\"#$%&'()*+,./:;<=>?@[\\]^_`{|}~"
    space :: CharSet
    space = String -> CharSet
    fromList " \t\r\n\v\f"
    xdigit :: CharSet
    xdigit = CharSet
    digit CharSet -> CharSet -> CharSet
    `union` Char -> Char -> CharSet
    range 'a' 'f' CharSet -> CharSet -> CharSet
    `union` Char -> Char -> CharSet
    range 'A' 'F'

    -- :digit:, etc.
    posixAscii :: HashMap String CharSet
    posixAscii :: HashMap String CharSet
    posixAscii = [(String, CharSet)] -> HashMap String CharSet
    forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
    HashMap.fromList
        [ ("alnum", CharSet
    alnum)
        , ("alpha", CharSet
    alpha)
        , ("ascii", CharSet
    ascii)
        , ("blank", CharSet
    blank)
        , ("cntrl", CharSet
    cntrl)
        , ("digit", CharSet
    digit)
        , ("graph", CharSet
    graph)
        , ("print", CharSet
    print)
        , ("word",  CharSet
    word)
        , ("punct", CharSet
    punct)
        , ("space", CharSet
    space)
        , ("upper", CharSet
    upper)
        , ("lower", CharSet
    lower)
        , ("xdigit", CharSet
    xdigit)
        ]

    lookupPosixAsciiCharSet :: String -> Maybe CharSet
    lookupPosixAsciiCharSet :: String -> Maybe CharSet
    lookupPosixAsciiCharSet s :: String
    s = String -> HashMap String CharSet -> Maybe CharSet
    forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
    HashMap.lookup ((Char -> Char) -> String -> String
    forall a b. (a -> b) -> [a] -> [b]
    Prelude.map Char -> Char
    toLower String
    s) HashMap String CharSet
    posixAscii