MODULE Utf8Prog; (* Utf8 codec: Encode/Decode round-trips. Exit 127. *) IMPORT Utf8; VAR ExitCode : INTEGER; VAR buf : ARRAY [0 .. 3] OF CHAR; VAR n : CARDINAL; VAR cp : UCHAR; VAR next : CARDINAL; BEGIN n := Utf8.Encode(U'é', buf); (* C3 A9 *) IF n = 2 THEN ExitCode := ExitCode + 1 ELSE ExitCode := 100 END; IF ORD(buf[0]) = 195 THEN ExitCode := ExitCode + 2 ELSE ExitCode := 100 END; IF ORD(buf[1]) = 169 THEN ExitCode := ExitCode + 4 ELSE ExitCode := 100 END; n := Utf8.Encode(U'😀', buf); (* F0 9F 98 80 *) IF n = 4 THEN ExitCode := ExitCode + 8 ELSE ExitCode := 100 END; IF ORD(buf[0]) = 240 THEN ExitCode := ExitCode + 16 ELSE ExitCode := 100 END; IF Utf8.Decode("é", 0, cp, next) THEN IF UORD(cp) = 233 THEN ExitCode := ExitCode + 32 ELSE ExitCode := 100 END; IF next = 2 THEN ExitCode := ExitCode + 64 ELSE ExitCode := 100 END ELSE ExitCode := 100 END END Utf8Prog.