[Overview][Constants][Types][Procedures and functions][Variables][Index] Reference for unit 'LConvEncoding' (#lazutils)

UTF8ToSingleByte

Converts a UTF-8-encoded string value to a single-bye character set using a conversion function.

Declaration

Source position: lconvencoding.pas line 203

function UTF8ToSingleByte(

  const s: string;

  const UTF8CharConvFunc: TUnicodeToCharID

):string;

Arguments

s

  

UTF-8-encoded string value converted in the routine.

UTF8CharConvFunc

  

Routine used translate Unicode code points to the singe-byte character set for the encoding.

Function result

String value after conversion to an encoding using a single-byte character set.

Description

UTF8ToSingleByte is used in an internal routine to convert the UTF-8-encoded value in s by calling the custom conversion routine in UTF8CharConvFunc. The return value is a string with the single-byte representation for the string value. UTF8ToSingleByte is called when the UseSystemCPConv compiler flag has not been defined for the platform, and system code pages are not available for the purpose.

No actions are performed in the routine when s is an empty string (''), and the return value is set to an empty string.

UTF8ToSingleByte iterates over the Unicode codepoints in s, and calls the routine in UTF8CharConvFunc for each of the codepoints. If a codepoint is not handled by the UTF8CodepointToUnicode routine, the value in ConvertEncodingErrorMode is used to determine the action taken for the character value. This includes:

ceemSkip
The character value is ignored.
ceemReplace
Inserts a '?' character for the unknown codepoint.
ceemReturnEmpty
Returns an empty string ('') for the conversion routine.
ceemException
Raises an EConvertError exception with the message 'Cannot convert UTF8 to single byte'.

UTF8ToSingleByte is called from an internal conversion routine, and occurs when the following routines are executed:

See also

ConvertEncodingFromUTF8

  

Converts the encoded value from UTF-8 to the encoding with the specified name.

ConvertEncoding

  

Converts the specified value from its source encoding to a target encoding using an optional code page.


Version 3.2 Generated 2024-02-25 Home