{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#if MIN_VERSION_lens(5,0,0)
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Short.Base16.Lens
(
_Hex
, _Base16
, _Base16Lenient
, pattern Hex
, pattern Base16
, pattern Base16Lenient
) where
import Control.Lens
import Data.ByteString.Short (ShortByteString)
import qualified Data.ByteString.Short.Base16 as B16S
_Base16 :: Prism' ShortByteString ShortByteString
_Base16 :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base16 = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
B16S.encodeBase16' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
B16S.decodeBase16 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base16 #-}
_Hex :: Prism' ShortByteString ShortByteString
_Hex :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Hex = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
B16S.encodeBase16' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
B16S.decodeBase16 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Hex #-}
_Base16Lenient :: Iso' ShortByteString ShortByteString
_Base16Lenient :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base16Lenient = (ShortByteString -> ShortByteString)
-> (ShortByteString -> ShortByteString)
-> Iso
ShortByteString ShortByteString ShortByteString ShortByteString
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ShortByteString -> ShortByteString
B16S.decodeBase16Lenient ShortByteString -> ShortByteString
B16S.encodeBase16'
{-# INLINE _Base16Lenient #-}
pattern Hex :: ShortByteString -> ShortByteString
pattern $bHex :: ShortByteString -> ShortByteString
$mHex :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Hex a <- (preview _Hex -> Just a) where
Hex ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Hex (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base16 :: ShortByteString -> ShortByteString
pattern $bBase16 :: ShortByteString -> ShortByteString
$mBase16 :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base16 a <- (preview _Base16 -> Just a) where
Base16 ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base16 (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base16Lenient :: ShortByteString -> ShortByteString
pattern $bBase16Lenient :: ShortByteString -> ShortByteString
$mBase16Lenient :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base16Lenient a <- (view _Base16Lenient -> a) where
Base16Lenient ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Iso ShortByteString ShortByteString ShortByteString ShortByteString
_Base16Lenient (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
{-# COMPLETE Base16Lenient #-}