Skip to content

Commit a1fd01d

Browse files
BodigrimLysxia
authored andcommitted
Add decodeUtf8Lenient for lazy Text
1 parent d2a183e commit a1fd01d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Data/Text/Lazy/Encoding.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

5960
import Control.Exception (evaluate, try)
6061
import Data.Monoid (Monoid(..))
61-
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
62+
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode, lenientDecode)
6263
import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldrChunks)
6364
import Data.Word (Word8)
6465
import 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.
148158
encodeUtf8 :: Text -> B.ByteString
149159
encodeUtf8 = foldrChunks (B.Chunk . TE.encodeUtf8) B.Empty

0 commit comments

Comments
 (0)