Documentation

UnicodeFormat.Iterator.UTF16

UTF-16 iterators #

UTF16.decodeIter reads characters from UTF-16 code units, and UTF16.encodeIter writes them back. An unpaired surrogate is ill-formed. A high surrogate reads its low surrogate by looking ahead; when there is none, only the high surrogate is ill-formed, and lossy decoding goes on from the next code unit.

structure Unicode.UTF16 :

The UTF-16 encoding form, as a decoder from code units and an encoder to code units.

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

      Decodes one character from the UTF-16 code units of it. Calls yield with the character and the iterator after it, error with the iterator after an unpaired surrogate, 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-16 code units of it, stopping at the first unpaired surrogate.

        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-16 code units of it, replacing each unpaired surrogate with U+FFFD.

          Equations
          Instances For
            @[inline]

            Encodes the characters of it as UTF-16 code units.

            Equations
            Instances For