module Data.Text.All
(
module Data.Text,
module Data.Text.IO,
module Data.Text.Encoding,
LText,
toStrict, toLazy,
toBuilder,
toString,
toByteString, toLByteString,
show, lshow, bshow,
module Data.Text.Format,
module Data.Text.Buildable,
format, lformat, bformat,
Builder,
bsingleton,
flush,
)
where
import Data.Text
import Data.Text.IO
import Data.Text.Encoding
import Data.Text.Encoding.Error
import qualified Data.Text.Lazy.Builder as B
import Data.Text.Lazy.Builder (Builder, flush)
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.UTF8 as UTF8
import qualified Data.ByteString.Lazy.UTF8 as UTF8L
import Data.Text.Format hiding (format, print, hprint, build)
import Data.Text.Format.Params
import Data.Text.Buildable
import qualified Data.Text.Format as Format
import qualified Prelude as P
import Prelude hiding (show)
type LText = TL.Text
show :: Show a => a -> Text
show = pack . P.show
lshow :: Show a => a -> LText
lshow = TL.pack . P.show
bshow :: Show a => a -> Builder
bshow = B.fromString . P.show
format :: Params ps => Format -> ps -> Text
format f = TL.toStrict . Format.format f
lformat :: Params ps => Format -> ps -> LText
lformat = Format.format
bformat :: Params ps => Format -> ps -> Builder
bformat = Format.build
class ToStrict t where
toStrict :: t -> Text
instance (a ~ Char) => ToStrict [a] where
toStrict = pack
instance ToStrict LText where
toStrict = TL.toStrict
instance ToStrict Builder where
toStrict = TL.toStrict . B.toLazyText
instance ToStrict BS.ByteString where
toStrict = decodeUtf8With lenientDecode
instance ToStrict BSL.ByteString where
toStrict = decodeUtf8With lenientDecode . BSL.toStrict
class ToLazy t where
toLazy :: t -> LText
instance (a ~ Char) => ToLazy [a] where
toLazy = TL.pack
instance ToLazy Text where
toLazy = TL.fromStrict
instance ToLazy Builder where
toLazy = B.toLazyText
instance ToLazy BS.ByteString where
toLazy = TL.fromStrict . decodeUtf8With lenientDecode
instance ToLazy BSL.ByteString where
toLazy = TL.decodeUtf8With lenientDecode
class ToBuilder t where
toBuilder :: t -> Builder
instance (a ~ Char) => ToBuilder [a] where
toBuilder = B.fromString
instance ToBuilder Text where
toBuilder = B.fromText
instance ToBuilder LText where
toBuilder = B.fromLazyText
instance ToBuilder BS.ByteString where
toBuilder = B.fromText . decodeUtf8With lenientDecode
instance ToBuilder BSL.ByteString where
toBuilder = B.fromLazyText . TL.decodeUtf8With lenientDecode
class ToString t where
toString :: t -> String
instance ToString Text where
toString = unpack
instance ToString LText where
toString = TL.unpack
instance ToString Builder where
toString = TL.unpack . B.toLazyText
instance ToString BS.ByteString where
toString = UTF8.toString
instance ToString BSL.ByteString where
toString = UTF8L.toString
class ToByteString t where
toByteString :: t -> BS.ByteString
instance ToByteString Text where
toByteString = encodeUtf8
instance ToByteString LText where
toByteString = encodeUtf8 . TL.toStrict
instance ToByteString Builder where
toByteString = encodeUtf8 . TL.toStrict . B.toLazyText
instance (a ~ Char) => ToByteString [a] where
toByteString = UTF8.fromString
class ToLByteString t where
toLByteString :: t -> BSL.ByteString
instance ToLByteString Text where
toLByteString = TL.encodeUtf8 . TL.fromStrict
instance ToLByteString LText where
toLByteString = TL.encodeUtf8
instance ToLByteString Builder where
toLByteString = TL.encodeUtf8 . B.toLazyText
instance (a ~ Char) => ToLByteString [a] where
toLByteString = UTF8L.fromString
bsingleton :: Char -> Builder
bsingleton = B.singleton