ConvertEncodingFromUTF8 function
Converts the encoded value from UTF-8 to the encoding with the specified name.
Declaration
function ConvertEncodingFromUTF8(const s: string;
const ToEncoding: string;
out Encoded: Boolean;
SetTargetCodePage: Boolean=False)
: stringArguments
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
- EncodingCPIso2 ('iso88592')
- UTF8ToISO_8859_2
- EncodingCPIso3 ('iso88593')
- UTF8ToISO_8859_3
- EncodingCPIso4 ('iso88594')
- UTF8ToISO_8859_4
- EncodingCPIso5 ('iso88595')
- UTF8ToISO_8859_5
- EncodingCPIso7 ('iso88597')
- UTF8ToISO_8859_7
- EncodingCPIso9 ('iso88599')
- UTF8ToISO_8859_9
- EncodingCPIso10 ('iso885910')
- UTF8ToISO_8859_10
- EncodingCPIso13 ('iso885913')
- UTF8ToISO_8859_13
- EncodingCPIso14 ('iso885914')
- UTF8ToISO_8859_14
- EncodingCPIso15 ('iso885915')
- UTF8ToISO_8859_15
- EncodingCPIso16 ('iso885916')
- UTF8ToISO_8859_16
- EncodingCP1250 ('cp1250')
- UTF8ToCP1250
- EncodingCP1251 ('cp1251')
- UTF8ToCP1251
- EncodingCP1252 ('cp1252')
- UTF8ToCP1252
- EncodingCP1253 ('cp1253')
- UTF8ToCP1253
- EncodingCP1254 ('cp1254')
- UTF8ToCP1254
- EncodingCP1255 ('cp1255')
- UTF8ToCP1255
- EncodingCP1256 ('cp1256')
- UTF8ToCP1256
- EncodingCP1257 ('cp1257')
- UTF8ToCP1257
- EncodingCP1258 ('cp1258')
- UTF8ToCP1258
- EncodingCP850 ('cp850')
- UTF8ToCP850
- EncodingCP852 ('cp852')
- UTF8ToCP852
- EncodingCP865 ('cp865')
- UTF8ToCP865
- EncodingCP866 ('cp866')
- UTF8ToCP866
- EncodingCP874 ('cp874')
- UTF8ToCP874
- EncodingCPKOI8R ('koi8r')
- UTF8ToKOI8R
- EncodingCPKOI8U ('koi8u')
- UTF8ToKOI8U
- EncodingCPKOI8RU ('koi8ru')
- UTF8ToKOI8RU
- EncodingCPMac ('macinstosh')
- UTF8ToMacinstosh
- EncodingUCS2LE ('ucs2le')
- UTF8ToUCS2LE
- EncodingUCS2BE ('ucs2be')
- UTF8ToUCS2BE
- 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
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
