Sign in Join
FPDoc Onlineexperiment

UTF8ToSingleByte function

In unit LConvEncoding

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

Declaration

pascal
function UTF8ToSingleByte(const s: string; 
 const UTF8CharConvFunc: TUnicodeToCharID)
: string

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:

  • UTF8ToISO_8859_1
  • UTF8ToISO_8859_2
  • UTF8ToISO_8859_3
  • UTF8ToISO_8859_4
  • UTF8ToISO_8859_5
  • UTF8ToISO_8859_7
  • UTF8ToISO_8859_9
  • UTF8ToISO_8859_10
  • UTF8ToISO_8859_13
  • UTF8ToISO_8859_14
  • UTF8ToISO_8859_15
  • UTF8ToCP1250
  • UTF8ToCP1251
  • UTF8ToCP1252
  • UTF8ToCP1253
  • UTF8ToCP1254
  • UTF8ToCP1255
  • UTF8ToCP1256
  • UTF8ToCP1257
  • UTF8ToCP1258
  • UTF8ToCP437
  • UTF8ToCP850
  • UTF8ToCP852
  • UTF8ToCP866
  • UTF8ToCP874
  • UTF8ToKOI8R
  • UTF8ToKOI8U
  • UTF8ToKOI8RU
  • UTF8ToMacintosh

See also

An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.