@@ -24,6 +24,7 @@ module Data.Text.Lazy.Encoding
2424 -- ** Total Functions #total#
2525 -- $total
2626 decodeLatin1
27+ , decodeUtf8Lenient
2728
2829 -- *** Catchable failure
2930 , decodeUtf8'
@@ -58,7 +59,7 @@ module Data.Text.Lazy.Encoding
5859
5960import Control.Exception (evaluate , try )
6061import Data.Monoid (Monoid (.. ))
61- import Data.Text.Encoding.Error (OnDecodeError , UnicodeException , strictDecode )
62+ import Data.Text.Encoding.Error (OnDecodeError , UnicodeException , strictDecode , lenientDecode )
6263import Data.Text.Internal.Lazy (Text (.. ), chunk , empty , foldrChunks )
6364import Data.Word (Word8 )
6465import qualified Data.ByteString.Builder as B
@@ -144,6 +145,15 @@ decodeUtf8' bs = unsafeDupablePerformIO $ do
144145 rnf (Chunk _ ts) = rnf ts
145146{-# INLINE decodeUtf8' #-}
146147
148+ -- | Decode a lazy 'ByteString' containing UTF-8 encoded text.
149+ --
150+ -- Any invalid input bytes will be replaced with the Unicode replacement
151+ -- character U+FFFD.
152+ --
153+ -- @since 2.1.4
154+ decodeUtf8Lenient :: B. ByteString -> Text
155+ decodeUtf8Lenient = decodeUtf8With lenientDecode
156+
147157-- | Encode text using UTF-8 encoding.
148158encodeUtf8 :: Text -> B. ByteString
149159encodeUtf8 = foldrChunks (B. Chunk . TE. encodeUtf8) B. Empty
0 commit comments