{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Fmt.Internal
(
FormatAsHex(..),
FormatAsBase64(..),
module Fmt.Internal.Core,
module Fmt.Internal.Formatters,
module Fmt.Internal.Template,
module Fmt.Internal.Tuple,
module Fmt.Internal.Numeric,
module Fmt.Internal.Generic,
)
where
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy.Encoding as TL
import qualified Formatting.Internal.Raw as F
import Data.Text.Lazy.Builder hiding (fromString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Base64.Lazy as B64L
import qualified Data.ByteString.Base64.URL as B64U
import qualified Data.ByteString.Base64.URL.Lazy as B64UL
import Fmt.Internal.Core
import Fmt.Internal.Formatters
import Fmt.Internal.Template
import Fmt.Internal.Tuple
import Fmt.Internal.Numeric
import Fmt.Internal.Generic
class FormatAsHex a where
hexF :: a -> Builder
instance FormatAsHex BS.ByteString where
hexF = fromLazyText . TL.decodeLatin1 . BB.toLazyByteString . BB.byteStringHex
instance FormatAsHex BSL.ByteString where
hexF = fromLazyText . TL.decodeLatin1 . BB.toLazyByteString . BB.lazyByteStringHex
instance {-# OVERLAPPABLE #-} Integral a => FormatAsHex a where
hexF = F.hex
class FormatAsBase64 a where
base64F :: a -> Builder
base64UrlF :: a -> Builder
instance FormatAsBase64 BS.ByteString where
base64F = fromText . T.decodeLatin1 . B64.encode
base64UrlF = fromText . T.decodeLatin1 . B64U.encode
instance FormatAsBase64 BSL.ByteString where
base64F = fromLazyText . TL.decodeLatin1 . B64L.encode
base64UrlF = fromLazyText . TL.decodeLatin1 . B64UL.encode