Sign in Join
FPDoc Onlineexperiment

LConvEncoding unit

Contains routines used to perform conversions between Unicode and System Code Page encodings.

lconvencoding.pas provides types, variable, constants, and routines used to perform conversions to and from Unicode and /or System Code Page encodings. Functions in this unit are thread-safe.

For environments where the RTL uses UTF-8 encoding, the UseSystemCPConv compiler define is enabled to include System Code Page conversions.

lconvencoding.pas is part of the LazUtils package.

Procedures and functions

ConvertEncodingfunctionConverts the specified value from its source encoding to a target encoding using an optional code page.
ConvertEncodingFromUTF8functionConverts the encoded value from UTF-8 to the encoding with the specified name.
ConvertEncodingToUTF8functionConverts the specified string value to the UTF-8 encoding.
CP1250ToUTF8functionConverts a Code Page 1250-encoded string to UTF-8.
CP1251ToUTF8functionConverts a Code Page 1251-encoded value to UTF-8.
CP1252ToUTF8functionConverts a Code Page 1252-encoded value to UTF-8.
CP1253ToUTF8functionConverts a Code Page 1253-encoded value to UTF-8.
CP1254ToUTF8functionConverts a Code Page 1254-encoded value to UTF-8.
CP1255ToUTF8functionConverts a Code Page 1255-encoded value to UTF-8.
CP1256ToUTF8functionConverts a Code Page 1256-encoded value to UTF-8.
CP1257ToUTF8functionConverts a Code Page 1257-encoded value to UTF-8.
CP1258ToUTF8functionConverts a Code Page 1258-encoded value to UTF-8.
CP437ToUTF8functionConverts a Code Page 437-encoded value to UTF-8.
CP850ToUTF8functionConverts a Code Page 850-encoded value to UTF-8.
CP852ToUTF8functionConverts a Code Page 852-encoded value to UTF-8.
CP865ToUTF8functionConverts a Code Page 852-encoded value to UTF-8.
CP866ToUTF8functionConverts a Code Page 866-encoded value to UTF-8.
CP874ToUTF8functionConverts a Code Page 874-encoded value to UTF-8.
CP932ToUTF8functionConverts a string value using Code Page 932 to UTF-8.
CP936ToUTF8functionConverts a string value using Code Page 936 to UTF-8.
CP949ToUTF8functionConverts a string value using Code Page 949 to UTF-8.
CP950ToUTF8functionConverts a string value using Code Page 950 to UTF-8.
GetConsoleTextEncodingfunctionGets the encoding used for a console application on the platform.
GetDefaultTextEncodingfunctionGets the name for the default text encoding used on the platform or operating system.
GetSupportedEncodingsprocedureAdds supported encoding names for the platform to the specified string list.
GuessEncodingfunctionTries to determine the encoding used for the specified value.
GuessPascalEncodingfunctionWorks like GuessEncoding but also supports {%encoding ...} directive.
ISO_8859_10ToUTF8functionConverts a string from its ISO 8859-10 (Latin-6) encoding to UTF-8 encoding.
ISO_8859_13ToUTF8functionConverts a string from its ISO 8859-13 (Latin-7) encoding to UTF-8 encoding.
ISO_8859_14ToUTF8functionConverts an ISO 8859-14-encoded string to UTF-8 encoding.
ISO_8859_15ToUTF8functionConverts an ISO 8859-15-encoded string to UTF-8.
ISO_8859_16ToUTF8functionConverts an ISO 8859-16-encoded string to UTF-8.
ISO_8859_1ToUTF8functionConverts an ISO 8859-1-encoded string to UTF-8.
ISO_8859_2ToUTF8functionConverts an ISO 8859-2-encoded string to UTF-8.
ISO_8859_3ToUTF8functionConverts an ISO 8859-3-encoded string to UTF-8.
ISO_8859_4ToUTF8functionConverts an ISO 8859-4-encoded string to UTF-8.
ISO_8859_5ToUTF8functionConverts an ISO 8859-5-encoded string to UTF-8.
ISO_8859_7ToUTF8functionConverts an ISO 8859-7-encoded string to UTF-8.
ISO_8859_9ToUTF8functionConverts a string from its ISO 8859-9 (Turkish) encoding to UTF-8 encoding.
KOI8RToUTF8functionConverts a KOI8-R-encoded value to UTF-8.
MacintoshToUTF8functionConverts a value encoded using the Macintosh Code Page to UTF-8.
NormalizeEncodingfunctionConverts the specified encoding name to lowercase and removes '-' characters.
SingleByteToUTF8functionConverts a string with single-byte values to UTF-8 using a character translation array.
UCS2BEToUTF8functionConverts a string from UCS 2-byte BE encoding to UTF-8.
UCS2LEToUTF8functionConverts a string from UCS 2-byte LE encoding to UTF-8.
UTF8BOMToUTF8functionRemoves the UTF-8 BOM from the UTF-8 encoded value.
UTF8ToCP1250functionConverts a string from UTF-8 encoding to Code Page 1250.
UTF8ToCP1251functionConverts a string from UTF-8 encoding to Code Page 1251.
UTF8ToCP1252functionConverts a string from UTF-8 encoding to Code Page 1252.
UTF8ToCP1253functionConverts a string from UTF-8 encoding to Code Page 1253.
UTF8ToCP1254functionConverts a string from UTF-8 encoding to Code Page 1254.
UTF8ToCP1255functionConverts a string from UTF-8 encoding to Code Page 1255.
UTF8ToCP1256functionConverts a string from UTF-8 encoding to Code Page 1256.
UTF8ToCP1257functionConverts a string from UTF-8 encoding to Code Page 1257.
UTF8ToCP1258functionConverts a string from UTF-8 encoding to Code Page 1258.
UTF8ToCP437functionConverts a string from UTF-8 encoding to Code Page 437.
UTF8ToCP850functionConverts a string from UTF-8 encoding to Code Page 850.
UTF8ToCP852functionConverts a string from UTF-8 encoding to Code Page 852.
UTF8ToCP865functionConverts a string from UTF-8 encoding to Code Page 865.
UTF8ToCP866functionConverts a string from UTF-8 encoding to Code Page 866.
UTF8ToCP874functionConverts a string from UTF-8 encoding to Code Page 874.
UTF8ToCP932functionConverts a string from UTF-8 encoding to Code Page 932.
UTF8ToCP936functionConverts a string from UTF-8 encoding to Code Page 936.
UTF8ToCP949functionConverts a string from UTF-8 encoding to Code Page 949.
UTF8ToCP950functionConverts a string from UTF-8 encoding to Code Page 950.
UTF8ToDBCSfunctionConverts a value from UTF-8 encoding to a Double Byte Character Set encoding.
UTF8ToISO_8859_1functionConverts a string from UTF-8 encoding to ISO 8859-1.
UTF8ToISO_8859_10functionConverts a string from UTF-8 encoding to ISO 8859-10 (Latin-6) encoding.
UTF8ToISO_8859_13functionConverts a string from UTF-8 encoding to ISO 8859-13 (Latin-7) encoding.
UTF8ToISO_8859_14functionConverts a string from UTF-8 encoding to ISO 8859-14.
UTF8ToISO_8859_15functionConverts a string from UTF-8 encoding to ISO 8859-15.
UTF8ToISO_8859_16functionConverts a string from UTF-8 encoding to ISO 8859-16.
UTF8ToISO_8859_2functionConverts a string from UTF-8 encoding to ISO 8859-2.
UTF8ToISO_8859_3functionConverts a string from UTF-8 encoding to ISO 8859-3.
UTF8ToISO_8859_4functionConverts a string from UTF-8 encoding to ISO 8859-3.
UTF8ToISO_8859_5functionConverts a string from UTF-8 encoding to ISO 8859-5.
UTF8ToISO_8859_7functionConverts a string from UTF-8 encoding to ISO 8859-7.
UTF8ToISO_8859_9functionConverts a string from UTF-8 encoding to ISO 8859-9 (Turkish) encoding.
UTF8ToKOI8RfunctionConverts a string from UTF-8 encoding to KOI8-R encoding.
UTF8ToKOI8RUfunctionConverts a string from UTF-8 encoding to KOI8-RU encoding.
UTF8ToKOI8UfunctionConverts a string from UTF-8 encoding to KOI8-U encoding.
UTF8ToMacintoshfunctionConverts a value from UTF-8 encoding to the Macintosh Code Page.
UTF8ToSingleBytefunctionConverts a UTF-8-encoded string value to a single-bye character set using a conversion function.
UTF8ToUCS2BEfunctionConverts a UTF-8-encoded value to UCS 2-byte Big Endian encoding.
UTF8ToUCS2LEfunctionConverts a UTF-8-encoded value to UCS 2-byte Little Endian encoding.
UTF8ToUTF8BOMfunctionConverts a string from UTF-8 encoding to UTF-8 with a Byte Order Mark.

Types

TCharToUTF8TabletypeAlias for the TCharToUTF8Table type in CodepagesCommon.pas.
TConvertEncodingErrorModeenumerationRepresents the behaviors for an error occurring in an encoding conversion.
TConvertEncodingFunctionprocedure typeSpecifies a function used to convert a single-byte string value to a specific multi-byte encoding.
TConvertUTF8ToEncodingFuncprocedure typeSpecifies a function used to convert a string value from UTF-8 encoding to another encoding with an optional code page.
TUnicodeToCharIDprocedure typeSpecifies an Integer function type used to get a character identifier for a specific Unicode character.

Constants

EncodingAnsiconstantEncoding name for ANSI.
EncodingCP1250constantEncoding name for Code Page 1250.
EncodingCP1251constantEncoding name for Code Page 1251.
EncodingCP1252constantEncoding name for Code Page 1252.
EncodingCP1253constantEncoding name for Code Page 1253.
EncodingCP1254constantEncoding name for Code Page 1254.
EncodingCP1255constantEncoding name for Code Page 1255.
EncodingCP1256constantEncoding name for Code Page 1256.
EncodingCP1257constantEncoding name for Code Page 1257.
EncodingCP1258constantEncoding name for Code Page 1258.
EncodingCP437constantEncoding name for Code Page 437.
EncodingCP850constantEncoding name for Code Page 850.
EncodingCP852constantEncoding name for Code Page 852.
EncodingCP865constantEncoding name for Code Page 865.
EncodingCP866constantEncoding name for Code Page 866.
EncodingCP874constantEncoding name for Code Page 874.
EncodingCP932constantEncoding name for Code Page 932.
EncodingCP936constantEncoding name for Code Page 936.
EncodingCP949constantEncoding name for Code Page 949.
EncodingCP950constantEncoding name for Code Page 950.
EncodingCPIso1constantEncoding name for ISO 8859-1 Code Page.
EncodingCPIso10constantEncoding name for ISO 8859-10 Code Page.
EncodingCPIso13constantEncoding name for ISO 8859-13 Code Page.
EncodingCPIso14constantEncoding name for ISO 8859-14 Code Page.
EncodingCPIso15constantEncoding name for ISO 8859-15 Code Page.
EncodingCPIso16constantEncoding name for ISO 8859-16 Code Page.
EncodingCPIso2constantEncoding name for ISO 8859-2 Code Page.
EncodingCPIso3constantEncoding name for ISO 8859-3 Code Page.
EncodingCPIso4constantEncoding name for ISO 8859-4 Code Page.
EncodingCPIso5constantEncoding name for ISO 8859-5 Code Page.
EncodingCPIso7constantEncoding name for ISO 8859-7 Code Page.
EncodingCPIso9constantEncoding name for ISO 8859-9 Code Page.
EncodingCPKOI8RconstantEncoding name for KOI8-R Code Page.
EncodingCPKOI8RUconstantEncoding name for KOI8-RU Code Page.
EncodingCPKOI8UconstantEncoding name for KOI8-U Code Page.
EncodingCPMacconstantEncoding name for the Macintosh Code Page.
EncodingUCS2BEconstantEncoding name for UCS 2-byte Big Endian.
EncodingUCS2LEconstantEncoding name for UCS 2-byte Little Endian.
EncodingUTF8constantEncoding name for UTF-8.
EncodingUTF8BOMconstantEncoding name for UTF-8 with a byte order mark.
UTF16BEBOMconstantANSI representation for the UTF-16 Big Endian Byte Order Mark.
UTF16LEBOMconstantANSI representation for the UTF-16 Little Endian Byte Order Mark.
UTF32BEBOMconstantANSI representation for the UTF-32 Big Endian Byte Order Mark.
UTF32LEBOMconstantANSI representation for the UTF-32 Little Endian Byte Order Mark.
UTF8BOMconstantANSI representation for the UTF-8 Byte Order Mark.

Variables

ConvertAnsiToUTF8variableContains the routine used to convert an ANSI string value to UTF-8 encoding.
ConvertEncodingErrorModevariableError handling behavior for encoding conversion errors.
ConvertUTF8ToAnsivariableContains the routine used to convert from UTF-8 encoding to ANSI encoding.

Uses

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