{-# LANGUAGE OverloadedStrings #-}
module Text.StringPrep.Profiles
( namePrepProfile
, saslPrepProfile
) where
import qualified Data.Set as Set
import Data.Text (Text, singleton)
import Text.StringPrep
namePrepProfile :: Bool -> StringPrepProfile
namePrepProfile :: Bool -> StringPrepProfile
namePrepProfile allowUnassigned :: Bool
allowUnassigned =
Profile :: [Map] -> Bool -> [Prohibited] -> Bool -> StringPrepProfile
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 [ '\x00A0', '\x1680', '\x2000', '\x2001', '\x2002'
, '\x2003', '\x2004', '\x2005', '\x2006', '\x2007'
, '\x2008', '\x2009', '\x200A', '\x200B', '\x202F'
, '\x205F', '\x3000'
]
toSpace :: Char -> Text
toSpace :: Map
toSpace x :: Char
x = if Char
x Char -> Set Char -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Char
nonAsciiSpaces then " " else Map
singleton Char
x
saslPrepProfile :: Bool -> StringPrepProfile
saslPrepProfile :: Bool -> StringPrepProfile
saslPrepProfile allowUnassigned :: Bool
allowUnassigned = Profile :: [Map] -> Bool -> [Prohibited] -> Bool -> StringPrepProfile
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
}