Class Utf8
java.lang.Object
org.libxmq.imp.ixml.earley.Utf8
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 TypeMethodDescriptionstatic intcodepoint(int decoded) The code point of a decode result.static intdecode(byte[] buf, int i, int stop) Decode the code point at buf[i].static StringdescribeInvalid(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 intlength(int decoded) The number of bytes of a decode result.
-
Method Details
-
decode
public static int decode(byte[] buf, int i, int stop) Decode the code point at buf[i].- Parameters:
buf- the bytesi- the index of the first byte of the code point, below stopstop- 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
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 bytesi- the start of the invalid sequencestop- the end of the input, exclusive- Returns:
- the bytes in hex
-