gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inquiring about the status of the proposed UNICODE library


From: Benjamin Kowarsch
Subject: Re: Inquiring about the status of the proposed UNICODE library
Date: Sun, 10 Mar 2024 22:38:21 +0900

Basically you need two functions

PROCEDURE utf8ToUnichar ( utf8 : ARRAY [0..5] OF CARDINAL [0..127]; VAR ch : UNICHAR );

PROCEDURE unicharToUtf8 ( ch : UNICHAR; VAR utf8 : ARRAY [0..5] OF CARDINAL [0..127] );

I just noticed that I made a mistake in the above function signatures. For UTF-8, the I/O buffer elements should be of type CARDINAL [0..255] instead of CARDINAL [0..127]. The latter would be for UTF-7.

BTW, for portability, you should avoid using SHORTCARD. Define a type for CARDINAL [0..255]. This will be portable.

You may also need a few utility functions such as:

PROCEDURE UCHR ( n : CARDINAL ) : UNICHAR;
(* Returns a UNICHAR value for code point n *)

PROCEDURE is7bitPrintable ( ch : UNICHAR ) : BOOLEAN;
(* Returns TRUE if ch represents a 7-bit printable character, else FALSE *)

PROCEDURE charFromUnichar ( ch : UNICHAR ) : CHAR;
(* Converts a UNICHAR value to type CHAR if ch is a 7-bit printable,
    causes a runtime error if ch does not represent a 7-bit printable *)

If you design the library for unqualified import, you may call the latter function toChar, calling it as Unichar.toChar().

regards
benjamin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]