Sign in Join
FPDoc Onlineexperiment

SingleByteToUTF8 function

In unit LConvEncoding

Converts a string with single-byte values to UTF-8 using a character translation array.

Declaration

pascal
function SingleByteToUTF8(const s: string; 
 const Table: TCharToUTF8Table): string

Arguments

s

String with the single-byte values converted in the routine.

Table

Table with Character to PChar mappings for the converted value.

Function result

String with the UTF-8-encoded value, or an empty string.

Description

s is the string, in its single-byte encoding, with the character values converted in the routine.

Table is a TCharToUTF8Table type and contains an array with the multi-byte values for each of the character using the UTF-8 encoding. The array has 256 elements representing #0 and each of the decimal values in the single byte character set, and may contain 1-4 byte values as needed for the UTF-8 encoding.

SingleByteToUTF8 iterates over the character values in s, and converts each single-byte character to the multi-byte value at the corresponding ordinal position in Table. If s is an empty string (''), the return value is also an empty string.

The return value is cast to a RawByteString type, and its code page is set to CP_UTF8 (65001).

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.