HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletext-2.1.3Haskell2010

Data.Text.Internal.Encoding

Warning: this is an internal module, and does not have a stable API or name. Functions in this module may not check or enforce preconditions expected by public modules. Use at your own risk!

Internals of Data.Text.Encoding.

  • 3 types
  • 12 values
  • Packagetext-2.1.3
  • Exports15
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceEncoding.hs

Validate another ByteString chunk in an ongoing stream of UTF-8-encoded text.

Returns a pair:

  1. The first component n is the end position, relative to the current chunk, of the longest prefix of the accumulated bytestring which is valid UTF-8. n may be negative: that happens when an incomplete code point started in a previous chunk and is not completed by the current chunk (either that code point is still incomplete, or it is broken by an invalid byte).

  2. The second component ms indicates the following:

    • if ms = Nothing, the remainder of the chunk contains an invalid byte, within four bytes from position n;

    • if ms = Just s', you can carry on validating another chunk by calling validateUtf8More with the new state s'.

Properties

Given:

validateUtf8More s chunk = (n, ms)

Decode another chunk in an ongoing UTF-8 stream.

Returns a triple:

  1. A StrictBuilder for the decoded chunk of text. You can accumulate chunks with (<>) or output them with toText.

  2. The undecoded remainder of the given chunk, for diagnosing errors and resuming (presumably after skipping some bytes).

  3. Just the new state, or Nothing if an invalid byte was encountered (it will be within the first 4 bytes of the undecoded remainder).

Properties

Given:

(pre, suf, ms) = decodeUtf8More s chunk
  1. If the output pre is nonempty (alternatively, if length chunk > length suf)

    s2b pre `append` suf = p2b s `append` chunk
    

    where

    s2b = encodeUtf8 . toText
    p2b = partUtf8ToByteString
    
  2. If the output pre is empty (alternatively, if length chunk = length suf)

    suf = chunk
  3. Decoding chunks separately is equivalent to decoding their concatenation.

    Given:

    (pre1, suf1, Just s1) = decodeUtf8More s chunk1
    (pre2, suf2,     ms2) = decodeUtf8More s1 chunk2
    (pre3, suf3,     ms3) = decodeUtf8More s (chunk1 `B.append` chunk2)
    

    we have:

    s2b (pre1 <> pre2) = s2b pre3
    ms2 = ms3
    
datadata StrictTextBuilder
#

A delayed representation of strict Text.

Instances2Semigroup, Monoid
  • Semigroup StrictTextBuilderDefined in text-2.1.3 · Data.Text.Internal.StrictBuilder

    Concatenation of StrictBuilder is right-biased: the right builder will be run first. This allows a builder to run tail-recursively when it was accumulated left-to-right.

  • Monoid StrictTextBuilderDefined in text-2.1.3 · Data.Text.Internal.StrictBuilder

Internal

3 declarations