Utf8.def 746 B

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