{-# OPTIONS -Wno-orphans #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TypeFamilies #-}
module Data.String.Interpolate.Conversion.ByteStringSink
()
where
import Data.Text.Conversions
import qualified Data.ByteString as B
import qualified Data.ByteString.Builder as LB
import qualified Data.ByteString.Lazy as LB
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT hiding ( singleton )
import qualified Data.Text.Lazy.Builder as LT
import Data.String.Interpolate.Conversion.Classes
import Data.String.Interpolate.Conversion.Encoding ( encodeCharUTF8 )
#ifdef BYTESTRING_BUILDER
instance InterpSink 'True B.ByteString where
type Builder 'True B.ByteString = LB.Builder
ofString _ = B . LB.byteString . unUTF8 . convertText
build _ (B l) (B r) = B $ l `mappend` r
finalize _ = LB.toStrict . LB.toLazyByteString . unB
instance InterpSink 'True LB.ByteString where
type Builder 'True LB.ByteString = LB.Builder
ofString _ = B . LB.lazyByteString . unUTF8 . convertText
build _ (B l) (B r) = B $ l `mappend` r
finalize _ = LB.toLazyByteString . unB
#else
instance InterpSink 'True B.ByteString where
type Builder 'True B.ByteString = B.ByteString
ofString :: Proxy 'True -> String -> B ByteString (Builder 'True ByteString)
ofString Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
build :: Proxy 'True
-> B ByteString (Builder 'True ByteString)
-> B ByteString (Builder 'True ByteString)
-> B ByteString (Builder 'True ByteString)
build Proxy 'True
_ (B Builder 'True ByteString
l) (B Builder 'True ByteString
r) = forall dst a. a -> B dst a
B forall a b. (a -> b) -> a -> b
$ Builder 'True ByteString
l forall a. Monoid a => a -> a -> a
`mappend` Builder 'True ByteString
r
finalize :: Proxy 'True
-> B ByteString (Builder 'True ByteString) -> ByteString
finalize Proxy 'True
_ = forall dst a. B dst a -> a
unB
instance InterpSink 'True LB.ByteString where
type Builder 'True LB.ByteString = LB.ByteString
ofString :: Proxy 'True -> String -> B ByteString (Builder 'True ByteString)
ofString Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
build :: Proxy 'True
-> B ByteString (Builder 'True ByteString)
-> B ByteString (Builder 'True ByteString)
-> B ByteString (Builder 'True ByteString)
build Proxy 'True
_ (B Builder 'True ByteString
l) (B Builder 'True ByteString
r) = forall dst a. a -> B dst a
B forall a b. (a -> b) -> a -> b
$ Builder 'True ByteString
l forall a. Monoid a => a -> a -> a
`mappend` Builder 'True ByteString
r
finalize :: Proxy 'True
-> B ByteString (Builder 'True ByteString) -> ByteString
finalize Proxy 'True
_ = forall dst a. B dst a -> a
unB
#endif
instance InterpSink 'True LB.Builder where
type Builder 'True LB.Builder = LB.Builder
ofString :: Proxy 'True -> String -> B Builder (Builder 'True Builder)
ofString Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
build :: Proxy 'True
-> B Builder (Builder 'True Builder)
-> B Builder (Builder 'True Builder)
-> B Builder (Builder 'True Builder)
build Proxy 'True
_ (B Builder 'True Builder
l) (B Builder 'True Builder
r) = forall dst a. a -> B dst a
B forall a b. (a -> b) -> a -> b
$ Builder 'True Builder
l forall a. Monoid a => a -> a -> a
`mappend` Builder 'True Builder
r
finalize :: Proxy 'True -> B Builder (Builder 'True Builder) -> Builder
finalize Proxy 'True
_ = forall dst a. B dst a -> a
unB
#ifdef BYTESTRING_BUILDER
instance {-# OVERLAPPABLE #-} Show src => Interpolatable 'True src B.ByteString where
interpolate _ = B . LB.byteString . unUTF8 . convertText . show
instance {-# OVERLAPS #-} Interpolatable 'True Char B.ByteString where
interpolate _ = B . encodeCharUTF8
instance {-# OVERLAPS #-} Interpolatable 'True String B.ByteString where
interpolate _ = B . LB.byteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True T.Text B.ByteString where
interpolate _ = B . LB.byteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Text B.ByteString where
interpolate _ = B . LB.byteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Builder B.ByteString where
interpolate _ = B . LB.byteString . unUTF8 . convertText . LT.toLazyText
instance {-# OVERLAPS #-} Interpolatable 'True B.ByteString B.ByteString where
interpolate _ = B . LB.byteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.ByteString B.ByteString where
interpolate _ = B . LB.lazyByteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.Builder B.ByteString where
interpolate _ = B
instance {-# OVERLAPPABLE #-} Show src => Interpolatable 'True src LB.ByteString where
interpolate _ = B . LB.lazyByteString . unUTF8 . convertText . show
instance {-# OVERLAPS #-} Interpolatable 'True Char LB.ByteString where
interpolate _ = B . encodeCharUTF8
instance {-# OVERLAPS #-} Interpolatable 'True String LB.ByteString where
interpolate _ = B . LB.lazyByteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True T.Text LB.ByteString where
interpolate _ = B . LB.lazyByteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Text LB.ByteString where
interpolate _ = B . LB.lazyByteString . unUTF8 . convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Builder LB.ByteString where
interpolate _ = B . LB.lazyByteString . unUTF8 . convertText . LT.toLazyText
instance {-# OVERLAPS #-} Interpolatable 'True B.ByteString LB.ByteString where
interpolate _ = B . LB.byteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.ByteString LB.ByteString where
interpolate _ = B . LB.lazyByteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.Builder LB.ByteString where
interpolate _ = B
#else
instance {-# OVERLAPPABLE #-} Show src => Interpolatable 'True src B.ByteString where
interpolate :: Proxy 'True -> src -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance {-# OVERLAPS #-} Interpolatable 'True Char B.ByteString where
interpolate :: Proxy 'True -> Char -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
LB.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
LB.toLazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Builder
encodeCharUTF8
instance {-# OVERLAPS #-} Interpolatable 'True String B.ByteString where
interpolate :: Proxy 'True -> String -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True T.Text B.ByteString where
interpolate :: Proxy 'True -> Text -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Text B.ByteString where
interpolate :: Proxy 'True -> Text -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Builder B.ByteString where
interpolate :: Proxy 'True -> Builder -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
LT.toLazyText
instance {-# OVERLAPS #-} Interpolatable 'True B.ByteString B.ByteString where
interpolate :: Proxy 'True
-> ByteString -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B
instance {-# OVERLAPS #-} Interpolatable 'True LB.ByteString B.ByteString where
interpolate :: Proxy 'True
-> ByteString -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
LB.toStrict
instance {-# OVERLAPS #-} Interpolatable 'True LB.Builder B.ByteString where
interpolate :: Proxy 'True -> Builder -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
LB.toStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
LB.toLazyByteString
instance {-# OVERLAPPABLE #-} Show src => Interpolatable 'True src LB.ByteString where
interpolate :: Proxy 'True -> src -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance {-# OVERLAPS #-} Interpolatable 'True Char LB.ByteString where
interpolate :: Proxy 'True -> Char -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
LB.toLazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Builder
encodeCharUTF8
instance {-# OVERLAPS #-} Interpolatable 'True String LB.ByteString where
interpolate :: Proxy 'True -> String -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True T.Text LB.ByteString where
interpolate :: Proxy 'True -> Text -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Text LB.ByteString where
interpolate :: Proxy 'True -> Text -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Builder LB.ByteString where
interpolate :: Proxy 'True -> Builder -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
LT.toLazyText
instance {-# OVERLAPS #-} Interpolatable 'True B.ByteString LB.ByteString where
interpolate :: Proxy 'True
-> ByteString -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
LB.fromStrict
instance {-# OVERLAPS #-} Interpolatable 'True LB.ByteString LB.ByteString where
interpolate :: Proxy 'True
-> ByteString -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B
instance {-# OVERLAPS #-} Interpolatable 'True LB.Builder LB.ByteString where
interpolate :: Proxy 'True -> Builder -> B ByteString (Builder 'True ByteString)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
LB.toLazyByteString
#endif
instance {-# OVERLAPPABLE #-} Show src => Interpolatable 'True src LB.Builder where
interpolate :: Proxy 'True -> src -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance {-# OVERLAPS #-} Interpolatable 'True Char LB.Builder where
interpolate :: Proxy 'True -> Char -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Builder
encodeCharUTF8
instance {-# OVERLAPS #-} Interpolatable 'True String LB.Builder where
interpolate :: Proxy 'True -> String -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True T.Text LB.Builder where
interpolate :: Proxy 'True -> Text -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Text LB.Builder where
interpolate :: Proxy 'True -> Text -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText
instance {-# OVERLAPS #-} Interpolatable 'True LT.Builder LB.Builder where
interpolate :: Proxy 'True -> Builder -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. UTF8 a -> a
unUTF8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (ToText a, FromText b) => a -> b
convertText forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Text
LT.toLazyText
instance {-# OVERLAPS #-} Interpolatable 'True B.ByteString LB.Builder where
interpolate :: Proxy 'True -> ByteString -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.byteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.ByteString LB.Builder where
interpolate :: Proxy 'True -> ByteString -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Builder
LB.lazyByteString
instance {-# OVERLAPS #-} Interpolatable 'True LB.Builder LB.Builder where
interpolate :: Proxy 'True -> Builder -> B Builder (Builder 'True Builder)
interpolate Proxy 'True
_ = forall dst a. a -> B dst a
B