HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduletext-2.1.3Haskell2010

Data.Text.Lazy.Encoding

Functions for converting lazy Text values to and from lazy ByteString, using several standard encodings.

To gain access to a much larger family of encodings, use the text-icu package.

  • 20 values
  • Packagetext-2.1.3
  • Exports20
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceEncoding.hs

Decoding ByteStrings to Text

0 declarations

All of the single-parameter functions for decoding bytestrings encoded in one of the Unicode Transformation Formats (UTF) operate in a strict mode: each will throw an exception if given invalid input.

Each function has a variant, whose name is suffixed with -With, that gives greater control over the handling of decoding errors. For instance, decodeUtf8 will throw an exception, but decodeUtf8With allows the programmer to determine what to do on a decoding error.

Total Functions

These functions facilitate total decoding and should be preferred over their partial counterparts.

Catchable failure

Decode a ByteString containing UTF-8 encoded text..

If the input contains any invalid UTF-8 data, the relevant exception will be returned, otherwise the decoded text.

Note: this function is not lazy, as it must decode its entire input before it can return a result. If you need lazy (streaming) decoding, use decodeUtf8With in lenient mode.

Controllable error handling

Partial Functions

These functions are partial and should only be used with great caution (preferably not at all). See Data.Text.Lazy.Encoding#g:total for better solutions.

valuedecodeUtf8 :: ByteString -> Text
#

Decode a ByteString containing UTF-8 encoded text that is known to be valid.

If the input contains any invalid UTF-8 data, an exception will be thrown that cannot be caught in pure code. For more control over the handling of invalid data, use decodeUtf8' or decodeUtf8With.

Decode text from little endian UTF-16 encoding.

If the input contains any invalid little endian UTF-16 data, an exception will be thrown. For more control over the handling of invalid data, use decodeUtf16LEWith.

Decode text from big endian UTF-16 encoding.

If the input contains any invalid big endian UTF-16 data, an exception will be thrown. For more control over the handling of invalid data, use decodeUtf16BEWith.

Decode text from little endian UTF-32 encoding.

If the input contains any invalid little endian UTF-32 data, an exception will be thrown. For more control over the handling of invalid data, use decodeUtf32LEWith.

Decode text from big endian UTF-32 encoding.

If the input contains any invalid big endian UTF-32 data, an exception will be thrown. For more control over the handling of invalid data, use decodeUtf32BEWith.

Encoding Text to ByteStrings

5 declarations

Encoding Text using ByteString Builders

2 declarations