{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#if MIN_VERSION_lens(5,0,0)
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Data.Text.Encoding.Base32.Lens
(
_Base32
, _Base32Unpadded
, _Base32Hex
, _Base32HexUnpadded
, pattern Base32
, pattern Base32Unpadded
, pattern Base32Hex
, pattern Base32HexUnpadded
) where
import Control.Lens
import Data.Text (Text)
import qualified Data.Text.Encoding.Base32 as B32T
import qualified Data.Text.Encoding.Base32.Hex as B32TH
_Base32 :: Prism' Text Text
_Base32 :: p Text (f Text) -> p Text (f Text)
_Base32 = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B32T.encodeBase32 ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B32T.decodeBase32 Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Base32 #-}
_Base32Unpadded :: Prism' Text Text
_Base32Unpadded :: p Text (f Text) -> p Text (f Text)
_Base32Unpadded = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B32T.encodeBase32Unpadded ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B32T.decodeBase32Unpadded Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Base32Unpadded #-}
_Base32Hex :: Prism' Text Text
_Base32Hex :: p Text (f Text) -> p Text (f Text)
_Base32Hex = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B32TH.encodeBase32 ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B32TH.decodeBase32 Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Base32Hex #-}
_Base32HexUnpadded :: Prism' Text Text
_Base32HexUnpadded :: p Text (f Text) -> p Text (f Text)
_Base32HexUnpadded = (Text -> Text) -> (Text -> Maybe Text) -> Prism Text Text Text Text
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' Text -> Text
B32TH.encodeBase32Unpadded ((Text -> Maybe Text) -> Prism Text Text Text Text)
-> (Text -> Maybe Text) -> Prism Text Text Text Text
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text -> Either Text Text
B32TH.decodeBase32Unpadded Text
s of
Left Text
_ -> Maybe Text
forall a. Maybe a
Nothing
Right Text
a -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
a
{-# INLINE _Base32HexUnpadded #-}
pattern Base32 :: Text -> Text
pattern $bBase32 :: Text -> Text
$mBase32 :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base32 a <- (preview _Base32 -> Just a) where
Base32 Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Base32 (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
pattern Base32Unpadded :: Text -> Text
pattern $bBase32Unpadded :: Text -> Text
$mBase32Unpadded :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base32Unpadded a <- (preview _Base32Unpadded -> Just a) where
Base32Unpadded Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Base32Unpadded (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
pattern Base32Hex :: Text -> Text
pattern $bBase32Hex :: Text -> Text
$mBase32Hex :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base32Hex a <- (preview _Base32Hex -> Just a) where
Base32Hex Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Base32Hex (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a
pattern Base32HexUnpadded :: Text -> Text
pattern $bBase32HexUnpadded :: Text -> Text
$mBase32HexUnpadded :: forall r. Text -> (Text -> r) -> (Void# -> r) -> r
Base32HexUnpadded a <- (preview _Base32HexUnpadded -> Just a) where
Base32HexUnpadded Text
a = Tagged Text (Identity Text) -> Tagged Text (Identity Text)
Prism Text Text Text Text
_Base32HexUnpadded (Tagged Text (Identity Text) -> Tagged Text (Identity Text))
-> Text -> Text
forall t b. AReview t b -> b -> t
# Text
a