Skip to content

Commit

Permalink
add decodeUtf8Lenient function
Browse files Browse the repository at this point in the history
  • Loading branch information
pearcedavis committed May 25, 2021
1 parent e24031e commit b42f915
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Data/Text/Encoding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Data.Text.Encoding

-- ** Controllable error handling
, decodeUtf8With
, decodeUtf8Lenient
, decodeUtf16LEWith
, decodeUtf16BEWith
, decodeUtf32LEWith
Expand Down Expand Up @@ -66,7 +67,7 @@ import Data.Bits ((.&.), shiftR)
import Data.ByteString as B
import qualified Data.ByteString.Internal as B
import Data.Foldable (traverse_)
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode)
import Data.Text.Encoding.Error (OnDecodeError, UnicodeException, strictDecode, lenientDecode)
import Data.Text.Internal (Text(..), safe, text)
import Data.Text.Internal.Functions
import Data.Text.Internal.Private (runText)
Expand Down Expand Up @@ -389,6 +390,13 @@ decodeUtf8' ::
decodeUtf8' = unsafeDupablePerformIO . try . evaluate . decodeUtf8With strictDecode
{-# INLINE decodeUtf8' #-}

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

-- | Encode text to a ByteString 'B.Builder' using UTF-8 encoding.
--
-- @since 1.1.0.0
Expand Down

0 comments on commit b42f915

Please sign in to comment.