on 3ebc7fa help sign in
text/Data/Text/Lazy/Encoding.hs
55 lines 1.6 kB history raw
1-- |
2-- Module : Data.Text.Lazy.Encoding
3-- Copyright : (c) Bryan O'Sullivan 2009
4--
5-- License : BSD-style
6-- Maintainer : bos@serpentine.com, rtharper@aftereternity.co.uk,
7-- duncan@haskell.org
8-- Stability : experimental
9-- Portability : portable
10--
11-- Functions for converting lazy 'Text' values to and from lazy
12-- 'ByteString', using several standard encodings.
13--
14-- To make use of a much larger variety of encodings, use the @text-icu@
15-- package.
17module Data.Text.Lazy.Encoding
18 (
19 -- * Decoding ByteStrings to Text
20 -- decodeASCII
21 decodeUtf8
22 , decodeUtf8With
23 --, decodeUtf16LE
24 --, decodeUtf16BE
25 --, decodeUtf32LE
26 --, decodeUtf32BE
28 -- * Encoding Text to ByteStrings
29 , encodeUtf8
30 --, encodeUtf16LE
31 --, encodeUtf16BE
32 --, encodeUtf32LE
33 --, encodeUtf32BE
34 ) where
36import Data.ByteString.Lazy (ByteString)
37import Data.Text.Encoding.Error (OnDecodeError, strictDecode)
38import Data.Text.Lazy (Text)
39import qualified Data.Text.Lazy.Fusion as F
40import qualified Data.Text.Lazy.Encoding.Fusion as E
42-- | Decode a 'ByteString' containing UTF-8 encoded text.
43decodeUtf8With :: OnDecodeError -> ByteString -> Text
44decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
45{-# INLINE decodeUtf8With #-}
47-- | Decode a 'ByteString' containing UTF-8 encoded text.
48decodeUtf8 :: ByteString -> Text
49decodeUtf8 = decodeUtf8With strictDecode
50{-# INLINE decodeUtf8 #-}
52-- | Encode text using UTF-8 encoding.
53encodeUtf8 :: Text -> ByteString
54encodeUtf8 txt = E.unstream (E.restreamUtf8 (F.stream txt))
55{-# INLINE encodeUtf8 #-}