UCS2LEToUTF8 function
Converts a string from UCS 2-byte LE encoding to UTF-8.
Declaration
function UCS2LEToUTF8(const s: string): stringArguments
s | String value using UCS2 LE encoding. |
Function result
String value after conversion to UTF-8 encoding.
Description
UCS2LEToUTF8 is a
String function used to convert a
value encoded using UCS2 LE (Little Endian) to its UTF-8 encoding. UCS2 is a
fixed-length encoding where each character is represented using 2 bytes
(16-bits). Byte values are stored in Least Significant (Little Endian) byte
order.
UCS2LEToUTF8 iterates over the characters in the string value, and converts
each character to the variable length multi-byte encoding used for characters
in UTF-8. LEToN is called to convert the byte values to the byte order used
for the platform. The UnicodeToUTF8SkipErrors routine in
lazutf8.pas is called to handle code points which are malformed,
require translation or are not used in UTF-8.
An exception is raised in UCS2LEToUTF8 if the length of the converted string is longer than 1.5 times the original string length.
The return value is cast to a RawByteString type, and SetCodePage is called to set the code page to CP_UTF8 (65001) in the result.
No actions are performed in the routine when s is an empty string (''), and the return value is an empty string.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
