Documentation

UnicodeFormat.Iterator.UTF8

UTF-8 iterators #

UTF8.decodeIter reads characters from UTF-8 bytes, and UTF8.encodeIter writes them back. The well-formed byte sequences are those of the Unicode Standard, Table 3-7. Ill-formed input is a maximal subpart: the longest prefix of a well-formed sequence that it starts with, or a single byte if none. Lossy decoding replaces each maximal subpart with U+FFFD, following the recommended practice of the Standard, Section 3.9.

UTF8.skipSignature skips the bytes EF BB BF that sometimes start UTF-8 data.

structure Unicode.UTF8 :

The UTF-8 encoding form, as a decoder from bytes and an encoder to bytes.

    Instances For
      @[inline]
      def Unicode.UTF8.decodeChar {ι : Type} [Std.Iterator ι Id UInt8] [Std.Iterators.Productive ι Id] {β : Type} (it : Std.Iter UInt8) (yield : (rest : Std.Iter UInt8) → Advanced rest it → Char → β) (error : DecodeError.Kind → (rest : Std.Iter UInt8) → Advanced rest it → β) (done : Unit → β) :
      β

      Decodes one character from the UTF-8 bytes of it. Calls yield with the character and the iterator after it, error with the iterator after a maximal subpart of an ill-formed byte sequence, or done at the end of the input.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        @[instance_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[instance_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        @[inline]

        Decodes the UTF-8 bytes of it, stopping at the first ill-formed byte sequence.

        A for loop or fold over the result ends at ill-formed input just as at the end of the input. To tell them apart, fold with decodeFold, which also returns the iterator where decoding stopped, and check decodeError? there, find the first ill-formed input ahead with decodeFailure?, or decode with decodeIterLossy instead.

        Equations
        Instances For
          @[inline]

          Decodes the UTF-8 bytes of it, replacing each maximal subpart of an ill-formed byte sequence with U+FFFD.

          Equations
          Instances For
            @[inline]

            Encodes the characters of it as UTF-8 bytes.

            Equations
            Instances For

              The iterator after the UTF-8 signature EF BB BF at it, or it if there is none.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For