~ubuntu-branches/ubuntu/wily/haskell-stringprep/wily

« back to all changes in this revision

Viewing changes to Text/StringPrep/Profiles.hs

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2015-06-04 10:33:11 UTC
  • mfrom: (3.1.3 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150604103311-g18t1sqyfx1dhxbj
Tags: 1.0.0-2build2
Rebuild for new GHC ABIs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# LANGUAGE OverloadedStrings #-}
 
2
 
 
3
-- | Profiles as defined by various sources
 
4
module Text.StringPrep.Profiles
 
5
  ( namePrepProfile
 
6
  , saslPrepProfile
 
7
  ) where
 
8
 
 
9
 
 
10
import qualified Data.Set as Set
 
11
import           Data.Text (Text, singleton)
 
12
import           Text.StringPrep
 
13
 
 
14
-- | Nameprep profile (RFC 3491)
 
15
namePrepProfile :: Bool -> StringPrepProfile
 
16
namePrepProfile allowUnassigned =
 
17
        Profile {
 
18
                maps = [b1,b2],
 
19
                shouldNormalize = True,
 
20
                prohibited = (if allowUnassigned then id else (a1:))
 
21
                               [c12,c22,c3,c4,c5,c6,c7,c8,c9],
 
22
                shouldCheckBidi = True
 
23
        }
 
24
 
 
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'
 
29
                              , '\x205F', '\x3000'
 
30
                              ]
 
31
 
 
32
 
 
33
toSpace :: Char -> Text
 
34
toSpace x = if x `Set.member` nonAsciiSpaces then " " else singleton x
 
35
 
 
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
 
45
    }