Documentation

UnicodeFormat.Iterator.Bytes

Byte order iterators #

The encoding schemes UTF-16BE, UTF-16LE, UTF-32BE and UTF-32LE serialize code units as bytes. ByteOrder.decodeIter16 reads UTF-16 code units from bytes and ByteOrder.encodeIter16 writes them, and likewise decodeIter32 and encodeIter32 for UTF-32. Bytes that end in the middle of a code unit are ill-formed; lossy decoding replaces that code unit with 0xFFFD, which decodes to U+FFFD.

To read characters from bytes, EncodingScheme.decodeIter is faster than decoding the code units of these iterators with UTF16.decodeIter or UTF32.decodeIter, about 3.5 times for UTF-16. It reads code units and characters in one layer. Over two layers, the compiler allocates the inner iterator for each character rather than update it in place.

The UTF-16 and UTF-32 schemes start with a byte order mark: ByteOrder.readBOM16 and readBOM32 read it, and give the byte order it tells and the iterator after it.

Code units of 2 bytes, in byte order order.

Instances For

    Code units of 4 bytes, in byte order order.

    Instances For
      @[inline]

      Byte i of the UTF-16 code unit u in byte order o.

      Equations
      Instances For
        @[inline]

        Byte i of the UTF-32 code unit u in byte order o.

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

          Reads one UTF-16 code unit from the bytes of it in byte order o. Calls yield with the code unit and the iterator after it, error with the iterator after an incomplete code unit at the end of the input, or done at the end of the input.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[inline]
            def Unicode.ByteOrder.readUInt32 {ι : Type} [Std.Iterator ι Id UInt8] [Std.Iterators.Productive ι Id] {β : Type} (o : ByteOrder) (it : Std.Iter UInt8) (yield : (rest : Std.Iter UInt8) → Advanced rest it → UInt32 → β) (error : DecodeError.Kind → (rest : Std.Iter UInt8) → Advanced rest it → β) (done : Unit → β) :
            β

            Reads one UTF-32 code unit from the bytes of it in byte order o. Calls yield with the code unit and the iterator after it, error with the iterator after an incomplete code unit at the end of the input, 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.
              @[instance_reducible]
              Equations
              @[instance_reducible]
              Equations
              @[inline]

              Decodes the bytes of it as UTF-16 code units in byte order o, stopping at an incomplete code unit.

              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 decodeIter16Lossy instead.

              Equations
              Instances For
                @[inline]

                Decodes the bytes of it as UTF-16 code units in byte order o, replacing an incomplete code unit with 0xFFFD.

                Equations
                Instances For
                  @[inline]

                  Encodes the UTF-16 code units of it as bytes in byte order o.

                  Equations
                  Instances For
                    @[inline]

                    Decodes the bytes of it as UTF-32 code units in byte order o, stopping at an incomplete code unit.

                    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 decodeIter32Lossy instead.

                    Equations
                    Instances For
                      @[inline]

                      Decodes the bytes of it as UTF-32 code units in byte order o, replacing an incomplete code unit with 0xFFFD.

                      Equations
                      Instances For
                        @[inline]

                        Encodes the UTF-32 code units of it as bytes in byte order o.

                        Equations
                        Instances For

                          The byte order given by the UTF-16 byte order mark at it, or o if there is none, and the iterator after the mark.

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

                            The byte order given by the UTF-32 byte order mark at it, or o if there is none, and the iterator after the mark.

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