    {-# LANGUAGE OverloadedStrings #-}

    -- | Profiles as defined by various sources
    module Text.StringPrep.Profiles
      ( namePrepProfile
      , saslPrepProfile
      ) where

    import qualified Data.Set as Set
    import           Data.Text (Text, singleton)
    import           Text.StringPrep

    -- | Nameprep profile (RFC 3491)
    namePrepProfile :: Bool -> StringPrepProfile
    namePrepProfile :: Bool -> StringPrepProfile
    namePrepProfile Bool
    allowUnassigned =
    	Profile {
    		maps :: [Map]
    maps = [Map
    b1,Map
    b2],
    		shouldNormalize :: Bool
    shouldNormalize = Bool
    True,
    		prohibited :: [Prohibited]
    prohibited = (if Bool
    allowUnassigned then [Prohibited] -> [Prohibited]
    forall a. a -> a
    id else (Prohibited
    a1Prohibited -> [Prohibited] -> [Prohibited]
    forall a. a -> [a] -> [a]
    :))
                                   [Prohibited
    c12,Prohibited
    c22,Prohibited
    c3,Prohibited
    c4,Prohibited
    c5,Prohibited
    c6,Prohibited
    c7,Prohibited
    c8,Prohibited
    c9],
    		shouldCheckBidi :: Bool
    shouldCheckBidi = Bool
    True
    	}

    nonAsciiSpaces :: Set.Set Char
    nonAsciiSpaces :: Set Char
    nonAsciiSpaces = [Char] -> Set Char
    forall a. Ord a => [a] -> Set a
    Set.fromList [ Char
    '\x00A0', Char
    '\x1680', Char
    '\x2000', Char
    '\x2001', Char
    '\x2002'
                                  , Char
    '\x2003', Char
    '\x2004', Char
    '\x2005', Char
    '\x2006', Char
    '\x2007'
                                  , Char
    '\x2008', Char
    '\x2009', Char
    '\x200A', Char
    '\x200B', Char
    '\x202F'
                                  , Char
    '\x205F', Char
    '\x3000'
                                  ]

    toSpace :: Char -> Text
    toSpace :: Map
    toSpace Char
    x = if Char
    x Char -> Set Char -> Bool
    forall a. Ord a => a -> Set a -> Bool
    `Set.member` Set Char
    nonAsciiSpaces then Text
    " " else Map
    singleton Char
    x

    -- | SASLPrep profile (RFC 4013). The parameter determines whether unassigned
    -- charater are allowed (query behaviour) or disallowed (store)
    saslPrepProfile :: Bool -> StringPrepProfile
    saslPrepProfile :: Bool -> StringPrepProfile
    saslPrepProfile Bool
    allowUnassigned = Profile
        { maps :: [Map]
    maps = [Map
    b1, Map
    toSpace]
        , shouldNormalize :: Bool
    shouldNormalize = Bool
    True
        , prohibited :: [Prohibited]
    prohibited = (if Bool
    allowUnassigned then [Prohibited] -> [Prohibited]
    forall a. a -> a
    id else (Prohibited
    a1Prohibited -> [Prohibited] -> [Prohibited]
    forall a. a -> [a] -> [a]
    :))
                          [Prohibited
    c12, Prohibited
    c21, Prohibited
    c22, Prohibited
    c3, Prohibited
    c4, Prohibited
    c5, Prohibited
    c6, Prohibited
    c7, Prohibited
    c8, Prohibited
    c9]
        , shouldCheckBidi :: Bool
    shouldCheckBidi = Bool
    True
        }