-- |-- Module : Data.String.Interpolate.Conversion-- Copyright : (c) William Yao, 2019-2020-- License : BSD-3-- Maintainer : williamyaoh@gmail.com-- Stability : experimental-- Portability : POSIX{-# OPTIONS -Wno-orphans #-}{-# LANGUAGE CPP #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE PackageImports #-}{-# LANGUAGE TypeFamilies #-}{-# LANGUAGE UndecidableInstances #-}{-# LANGUAGE Strict #-}module Data.String.Interpolate.Conversion ( IsCustomSink, InterpSink(..), Interpolatable(..) , bsToTextBuilder, lbsToTextBuilder, encodeCharUTF8 )whereimport Data.String ( IsString, fromString )import qualified Data.ByteString as Bimport qualified Data.ByteString.Builder as LBimport qualified Data.ByteString.Lazy as LBimport qualified Data.Text as Timport qualified Data.Text.Lazy as LT hiding ( singleton )import qualified Data.Text.Lazy.Builder as LTimport qualified "utf8-string" Data.ByteString.Lazy.UTF8 as LUTF8import qualified "utf8-string" Data.ByteString.UTF8 as UTF8import Data.String.Interpolate.Conversion.Classesimport Data.String.Interpolate.Conversion.Encodingimport Data.String.Interpolate.Conversion.TextSink ()import Data.String.Interpolate.Conversion.ByteStringSink ()-- Remove some imports above GHC 8.8.X#if MIN_VERSION_base(4,13,0)#elseimport "base" Text.Show ( ShowS, showChar, showString )#endifinstance (IsCustomSink str ~ 'False, IsString str) => InterpSink 'False str where type Builder 'False str = ShowS ofString _ = B . showString build _ (B f) (B g) = B $ f . g finalize _ = fromString . ($ "") . unBinstance {-# OVERLAPPABLE #-} (Show src, IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False src dst where interpolate _ = B . showsinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False Char dst where interpolate _ = B . showCharinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False String dst where interpolate _ = B . showStringinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False T.Text dst where interpolate _ = B . showString . T.unpackinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False LT.Text dst where interpolate _ = B . showString . LT.unpackinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False LT.Builder dst where interpolate _ = B . showString . LT.unpack . LT.toLazyTextinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False B.ByteString dst where interpolate _ = B . showString . UTF8.toStringinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False LB.ByteString dst where interpolate _ = B . showString . LUTF8.toStringinstance {-# OVERLAPS #-} (IsString dst, IsCustomSink dst ~ 'False) => Interpolatable 'False LB.Builder dst where interpolate _ = B . showString . LUTF8.toString . LB.toLazyByteString