Class Utf8

java.lang.Object
org.libxmq.imp.ixml.earley.Utf8

public final class Utf8 extends Object
Decode UTF-8 directly from a byte buffer, one code point at a time. The ixml input is never turned into a String (two bytes per char) or an int[] (four bytes per code point), the parser reads the code points from the bytes. Invalid UTF-8 is rejected like find_invalid_utf8 in the C version: a stray continuation byte, a truncated sequence, an overlong encoding, a surrogate or above U+10FFFF.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    codepoint(int decoded)
    The code point of a decode result.
    static int
    decode(byte[] buf, int i, int stop)
    Decode the code point at buf[i].
    static String
    describeInvalid(byte[] buf, int i, int stop)
    The bytes of the invalid sequence at buf[i], as the C version prints them: 0xC3 0x28, the first byte and up to three continuation bytes after it.
    static int
    length(int decoded)
    The number of bytes of a decode result.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • decode

      public static int decode(byte[] buf, int i, int stop)
      Decode the code point at buf[i].
      Parameters:
      buf - the bytes
      i - the index of the first byte of the code point, below stop
      stop - the end of the input, exclusive
      Returns:
      the code point in the low 21 bits and the number of bytes (1-4) above them, see codepoint() and length(), or -1 if the bytes at i are not valid UTF-8
    • codepoint

      public static int codepoint(int decoded)
      The code point of a decode result.
      Parameters:
      decoded - from decode, not -1
      Returns:
      the code point
    • length

      public static int length(int decoded)
      The number of bytes of a decode result.
      Parameters:
      decoded - from decode, not -1
      Returns:
      1 to 4
    • describeInvalid

      public static String describeInvalid(byte[] buf, int i, int stop)
      The bytes of the invalid sequence at buf[i], as the C version prints them: 0xC3 0x28, the first byte and up to three continuation bytes after it.
      Parameters:
      buf - the bytes
      i - the start of the invalid sequence
      stop - the end of the input, exclusive
      Returns:
      the bytes in hex