DEFINITION MODULE Utf8; (* Strict RFC3629 UTF-8 codec, shared by the front end and the text output libraries. Codepoints are UCHAR scalars. *) CONST MaxUTF8Length = 4; MaxCodePoint = 1114111; PROCEDURE Decode (s : ARRAY OF CHAR; lo : CARDINAL; VAR cp : UCHAR; VAR next : CARDINAL) : BOOLEAN; (* Decode one sequence starting at s[lo]: cp := the codepoint, next := the index just past it. FALSE on malformed or truncated input (overlong, surrogate, > MaxCodePoint, bad continuation byte). *) PROCEDURE Encode (cp : UCHAR; VAR buf : ARRAY OF CHAR) : CARDINAL; (* Encode cp as UTF-8 into buf[0..]; returns the byte count (0 when cp is not a Unicode scalar value). buf needs MaxUTF8Length slots. *) END Utf8.