Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Data/Text/Lazy/Encoding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Data.Text.Lazy.Encoding
-- ** Total Functions #total#
-- $total
decodeLatin1
, decodeUtf8Lenient

-- *** Catchable failure
, decodeUtf8'
Expand Down Expand Up @@ -58,7 +59,7 @@ module Data.Text.Lazy.Encoding

import Control.Exception (evaluate, try)
import Data.Monoid (Monoid(..))
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode, lenientDecode)
import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldrChunks)
import Data.Word (Word8)
import qualified Data.ByteString.Builder as B
Expand Down Expand Up @@ -144,6 +145,15 @@ decodeUtf8' bs = unsafeDupablePerformIO $ do
rnf (Chunk _ ts) = rnf ts
{-# INLINE decodeUtf8' #-}

-- | Decode a lazy 'ByteString' containing UTF-8 encoded text.
--
-- Any invalid input bytes will be replaced with the Unicode replacement
-- character U+FFFD.
--
-- @since 2.1.4
decodeUtf8Lenient :: B.ByteString -> Text
decodeUtf8Lenient = decodeUtf8With lenientDecode

-- | Encode text using UTF-8 encoding.
encodeUtf8 :: Text -> B.ByteString
encodeUtf8 = foldrChunks (B.Chunk . TE.encodeUtf8) B.Empty
Expand Down