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

ConvertEncodingFromUTF8

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

Declaration

Source position: lconvencoding.pas line 100

function ConvertEncodingFromUTF8(

  const s: string;

  const ToEncoding: string;

  out Encoded: Boolean;

  SetTargetCodePage: Boolean = False

):string;

Arguments

s

  

UTF-8-encoded value converted in the routine.

ToEncoding

  

Encoding name for the converted value.

Encoded

  

True if the return value contains multi-byte encoded values, False if it contains a single-byte ANSI string.

SetTargetCodePage

  

True if the code page should be set for the return value, False if a code page is not used.

Function result

String value after conversion to the specified encoding.

Description

The s argument contains the UTF-8-encoded value converted in the routine.

ToEncoding is a String value with the name for the target encoding. 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')
UTF8ToUTF8BOM
EncodingCPIso1 ('iso88591')
UTF8ToISO_8859_1
EncodingCP1250 ('cp1250')
UTF8ToCP1250
EncodingCP1252 ('cp1252')
UTF8ToCP1252
EncodingCP850 ('cp850')
UTF8ToCP850
EncodingCPKOI8R ('koi8r')
UTF8ToKOI8R
EncodingAnsi ('ansi')
ConvertUTF8ToAnsi

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 target encoding in ToEncoding.

SetTargetCodePage is a Boolean argument which indicates if SetCodePage is called to apply a translated code page for the converted value. The default value for the argument is False, and omits the code page for the return value.

ConvertEncodingFromUTF8 is used in the implementation of the ConvertEncoding function.

See also

ConvertEncoding

  

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

NormalizeEncoding

  

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

ConvertEncodingToUTF8

  

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