1
{-# LANGUAGE OverloadedStrings #-}
3
-- | Profiles as defined by various sources
4
module Text.StringPrep.Profiles
10
import qualified Data.Set as Set
11
import Data.Text (Text, singleton)
12
import Text.StringPrep
14
-- | Nameprep profile (RFC 3491)
15
namePrepProfile :: Bool -> StringPrepProfile
16
namePrepProfile allowUnassigned =
19
shouldNormalize = True,
20
prohibited = (if allowUnassigned then id else (a1:))
21
[c12,c22,c3,c4,c5,c6,c7,c8,c9],
22
shouldCheckBidi = True
25
nonAsciiSpaces :: Set.Set Char
26
nonAsciiSpaces = Set.fromList [ '\x00A0', '\x1680', '\x2000', '\x2001', '\x2002'
27
, '\x2003', '\x2004', '\x2005', '\x2006', '\x2007'
28
, '\x2008', '\x2009', '\x200A', '\x200B', '\x202F'
33
toSpace :: Char -> Text
34
toSpace x = if x `Set.member` nonAsciiSpaces then " " else singleton x
36
-- | SASLPrep profile (RFC 4013). The parameter determines whether unassigned
37
-- charater are allowed (query behaviour) or disallowed (store)
38
saslPrepProfile :: Bool -> StringPrepProfile
39
saslPrepProfile allowUnassigned = Profile
40
{ maps = [b1, toSpace]
41
, shouldNormalize = True
42
, prohibited = (if allowUnassigned then id else (a1:))
43
[c12, c21, c22, c3, c4, c5, c6, c7, c8, c9]
44
, shouldCheckBidi = True