diff --git a/Data/Text/Encoding.hs b/Data/Text/Encoding.hs index 1db9dd8e..a0c2253d 100644 --- a/Data/Text/Encoding.hs +++ b/Data/Text/Encoding.hs @@ -34,6 +34,10 @@ module Data.Text.Encoding -- ** Catchable failure , decodeUtf8' + , decodeUtf16LE' + , decodeUtf16BE' + , decodeUtf32LE' + , decodeUtf32BE' -- ** Controllable error handling , decodeUtf8With @@ -401,6 +405,14 @@ decodeUtf16LE :: ByteString -> Text decodeUtf16LE = decodeUtf16LEWith strictDecode {-# INLINE decodeUtf16LE #-} +-- | Decode a 'ByteString' containing little endian UTF-16 encoded text. +-- +-- If the input contains any invalid little endian UTF-16 data, the relevant +-- exception will be returned, otherwise the decoded text. +decodeUtf16LE' :: ByteString -> Either UnicodeException Text +decodeUtf16LE' = unsafeDupablePerformIO . try . evaluate . decodeUtf16LEWith strictDecode +{-# INLINE decodeUtf16LE' #-} + -- | Decode text from big endian UTF-16 encoding. decodeUtf16BEWith :: OnDecodeError -> ByteString -> Text decodeUtf16BEWith onErr bs = F.unstream (E.streamUtf16BE onErr bs) @@ -415,6 +427,14 @@ decodeUtf16BE :: ByteString -> Text decodeUtf16BE = decodeUtf16BEWith strictDecode {-# INLINE decodeUtf16BE #-} +-- | Decode a 'ByteString' containing big endian UTF-16 encoded text. +-- +-- If the input contains any invalid big endian UTF-16 data, the relevant +-- exception will be returned, otherwise the decoded text. +decodeUtf16BE' :: ByteString -> Either UnicodeException Text +decodeUtf16BE' = unsafeDupablePerformIO . try . evaluate . decodeUtf16BEWith strictDecode +{-# INLINE decodeUtf16BE' #-} + -- | Encode text using little endian UTF-16 encoding. encodeUtf16LE :: Text -> ByteString encodeUtf16LE txt = E.unstream (E.restreamUtf16LE (F.stream txt)) @@ -439,6 +459,14 @@ decodeUtf32LE :: ByteString -> Text decodeUtf32LE = decodeUtf32LEWith strictDecode {-# INLINE decodeUtf32LE #-} +-- | Decode a 'ByteString' containing little endian UTF-32 encoded text. +-- +-- If the input contains any invalid little endian UTF-32 data, the relevant +-- exception will be returned, otherwise the decoded text. +decodeUtf32LE' :: ByteString -> Either UnicodeException Text +decodeUtf32LE' = unsafeDupablePerformIO . try . evaluate . decodeUtf32LEWith strictDecode +{-# INLINE decodeUtf32LE' #-} + -- | Decode text from big endian UTF-32 encoding. decodeUtf32BEWith :: OnDecodeError -> ByteString -> Text decodeUtf32BEWith onErr bs = F.unstream (E.streamUtf32BE onErr bs) @@ -453,6 +481,14 @@ decodeUtf32BE :: ByteString -> Text decodeUtf32BE = decodeUtf32BEWith strictDecode {-# INLINE decodeUtf32BE #-} +-- | Decode a 'ByteString' containing big endian UTF-32 encoded text. +-- +-- If the input contains any invalid big endian UTF-32 data, the relevant +-- exception will be returned, otherwise the decoded text. +decodeUtf32BE' :: ByteString -> Either UnicodeException Text +decodeUtf32BE' = unsafeDupablePerformIO . try . evaluate . decodeUtf32BEWith strictDecode +{-# INLINE decodeUtf32BE' #-} + -- | Encode text using little endian UTF-32 encoding. encodeUtf32LE :: Text -> ByteString encodeUtf32LE txt = E.unstream (E.restreamUtf32LE (F.stream txt))