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

ConvertEncodingToUTF8

Converts the specified string value to the UTF-8 encoding.

Declaration

Source position: lconvencoding.pas line 102

function ConvertEncodingToUTF8(

  const s: string;

  const FromEncoding: string;

  out Encoded: Boolean

):string;

Arguments

s

  

String with the encoded value converted to UTF-8.

FromEncoding

  

Encoding name for the value in s.

Encoded

  

True if the result contains a multi-byte encoded value. Always True for conversions to UTF-8.

Function result

Value for the specified string after encoding conversion.

Description

ConvertEncodingToUTF8 converts the encoding for a string value from the specified encoding to UTF-8. The s argument contains the string value converted in the routine.

FromEncoding is a String value with the name for the existing encoding is s. It is normalized in the routine to remove hyphen characters in the encoding name. The value corresponds to the encoding name constants defined in the unit, and is used to determine which routine is called to perform the encoding conversion.

For example, the following is a sample of the encoding names and their corresponding conversion routines:

EncodingUTF8BOM ('utf8bom')
UTF8BOMToUTF8
EncodingCPIso1 ('iso88591')
ISO_8859_1ToUTF8
EncodingCP1250 ('cp1250')
CP1250ToUTF8
EncodingCP1252 ('cp1252')
CP1252ToUTF8
EncodingCP850 ('cp850')
CP850ToUTF8
EncodingCPKOI8R ('koi8r')
KOI8RToUTF8
EncodingAnsi ('ansi') or the default text encoding for the platform
ConvertAnsiToUTF8

Encoded is a Boolean output parameter which indicates if a routine was found to perform the requested conversion. Its value is False when a conversion routine was not found for the source encoding in FromEncoding.

ConvertEncodingToUTF8 is used in the implementation of the ConvertEncoding function.

Remark: Conversions to the UTF-8 encoding will always set the code page for the converted value to CP_UTF8 (65001). In other words, the SetTargetCodePage argument to the ConvertEncoding() function is ignored for conversions to UTF-8.

See also

ConvertEncoding

  

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

ConvertEncodingFromUTF8

  

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

ConvertAnsiToUTF8

  

Contains the routine used to convert an ANSI string value to UTF-8 encoding.

NormalizeEncoding

  

Converts the specified encoding name to lowercase and removes '-' characters.

GetDefaultTextEncoding

  

Gets the name for the default text encoding used on the platform or operating system.