#line 22 "src/util.anansi"
#line 30 "src/introduction.anansi"
#line 23 "src/util.anansi"
module DBus.UUID
( UUID
, toHex
, fromHex
) where
#line 56 "src/introduction.anansi"
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as TL
#line 29 "src/util.anansi"
newtype UUID = UUID Text
deriving (Eq)
instance Show UUID where
showsPrec d uuid = showParen (d > 10) $
showString "UUID " . shows (toHex uuid)
toHex :: UUID -> Text
toHex (UUID text) = text
fromHex :: Text -> Maybe UUID
fromHex text = if validUUID text
then Just $ UUID text
else Nothing
validUUID :: Text -> Bool
validUUID text = valid where
valid = and [TL.length text == 32, TL.all validChar text]
validChar c = or
[ c >= '0' && c <= '9'
, c >= 'a' && c <= 'f'
, c >= 'A' && c <= 'F'
]