~alcinnz/fontconfig-pure

ref: a7c384b2408f2a512ecaee9d1287a9bbf5d41290 fontconfig-pure/lib/Graphics/Text/Font/Choose/StrSet.hs -rw-r--r-- 619 bytes
a7c384b2 — Adrian Cochrane Improve handling of invalid FontConfig data. 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Graphics.Text.Font.Choose.StrSet(StrSet(..), module S, validStrSet) where

import Data.Set (Set)
import qualified Data.Set as S

import Data.MessagePack (MessagePack(..))
import Test.QuickCheck (Arbitrary(..))

newtype StrSet = StrSet { unStrSet :: Set String } deriving (Eq, Show, Read)

instance MessagePack StrSet where
    toObject = toObject . S.toList . unStrSet
    fromObject msg = StrSet <$> S.fromList <$> fromObject msg
instance Arbitrary StrSet where
    arbitrary = StrSet <$> S.map (filter (/= '\0')) <$> arbitrary

validStrSet :: StrSet -> Bool
validStrSet (StrSet self) = notElem '\0' `all` self