module Data.Convertible.Instances.Text()
where
import Data.Convertible.Base
import qualified Data.Text as TS
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TLB
import qualified Data.Text.Lazy.Encoding as TLE
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Builder as BB
import Data.Word (Word8)
import Data.Foldable
instance Convertible TS.Text [Char] where
safeConvert = Right . TS.unpack
instance Convertible TS.Text TL.Text where
safeConvert = Right . TL.fromStrict
instance Convertible TS.Text TLB.Builder where
safeConvert = Right . TLB.fromText
instance Convertible TS.Text BS.ByteString where
safeConvert = Right . TE.encodeUtf8
instance Convertible TS.Text BL.ByteString where
safeConvert = Right . BL.fromStrict . TE.encodeUtf8
instance Convertible TS.Text BB.Builder where
#if MIN_VERSION_text(1,2,0)
safeConvert = Right . TE.encodeUtf8Builder
#else
safeConvert = safeConvert . TE.encodeUtf8
#endif
instance Convertible TL.Text [Char] where
safeConvert = Right . TL.unpack
instance Convertible TL.Text TS.Text where
safeConvert = Right . TL.toStrict
instance Convertible TL.Text TLB.Builder where
safeConvert = Right . TLB.fromLazyText
instance Convertible TL.Text BS.ByteString where
safeConvert = safeConvert . TLE.encodeUtf8
instance Convertible TL.Text BL.ByteString where
safeConvert = Right . TLE.encodeUtf8
instance Convertible TL.Text BB.Builder where
#if MIN_VERSION_text(1,2,0)
safeConvert = Right . TLE.encodeUtf8Builder
#else
safeConvert = safeConvert . TLE.encodeUtf8
#endif
instance Convertible TLB.Builder [Char] where
safeConvert = safeConvert . TLB.toLazyText
instance Convertible TLB.Builder TS.Text where
safeConvert = safeConvert . TLB.toLazyText
instance Convertible TLB.Builder TL.Text where
safeConvert = Right . TLB.toLazyText
instance Convertible TLB.Builder BS.ByteString where
safeConvert = safeConvert . TLB.toLazyText
instance Convertible TLB.Builder BL.ByteString where
safeConvert = safeConvert . TLB.toLazyText
instance Convertible TLB.Builder BB.Builder where
safeConvert = safeConvert . TLB.toLazyText
instance Convertible BS.ByteString [Word8] where
safeConvert = Right . BS.unpack
instance Convertible BS.ByteString TS.Text where
safeConvert = Right . TE.decodeUtf8
instance Convertible BS.ByteString TL.Text where
safeConvert = fmap TL.fromStrict . safeConvert
instance Convertible BS.ByteString TLB.Builder where
safeConvert = fmap TLB.fromText . safeConvert
instance Convertible BS.ByteString BL.ByteString where
safeConvert = Right . BL.fromStrict
instance Convertible BS.ByteString BB.Builder where
safeConvert = Right . BB.byteString
instance Convertible BL.ByteString [Word8] where
safeConvert = Right . BL.unpack
instance Convertible BL.ByteString TS.Text where
safeConvert = fmap TL.toStrict . safeConvert
instance Convertible BL.ByteString TL.Text where
safeConvert = Right . TLE.decodeUtf8
instance Convertible BL.ByteString TLB.Builder where
safeConvert = fmap TLB.fromLazyText . safeConvert
instance Convertible BL.ByteString BS.ByteString where
safeConvert = Right . BL.toStrict
instance Convertible BL.ByteString BB.Builder where
safeConvert = Right . BB.lazyByteString
instance Convertible [Char] TS.Text where
safeConvert = Right . TS.pack
instance Convertible [Char] TL.Text where
safeConvert = Right . TL.pack
instance Convertible [Char] TLB.Builder where
safeConvert = Right . TLB.fromString
instance Convertible [Word8] BS.ByteString where
safeConvert = Right . BS.pack
instance Convertible [Word8] BL.ByteString where
safeConvert = Right . BL.pack
instance Convertible [Word8] BB.Builder where
safeConvert = Right . foldMap BB.word8
instance Convertible Char TS.Text where
safeConvert = Right . TS.singleton
instance Convertible Char TL.Text where
safeConvert = Right . TL.singleton
instance Convertible Char TLB.Builder where
safeConvert = Right . TLB.singleton
instance Convertible Word8 BS.ByteString where
safeConvert = Right . BS.singleton
instance Convertible Word8 BL.ByteString where
safeConvert = Right . BL.singleton
instance Convertible Word8 BB.Builder where
safeConvert = Right . BB.word8