Encode::Unicode#

📦 std

The XS half of Encode::Unicode: the UTF-16, UTF-32 and UCS-2 codecs.

Encode/Unicode.pm (served verbatim from lib/) creates one blessed hash per encoding - Name, size, endian, ucs2 - and registers it with Encode::define_encoding. The two methods below read those attributes and convert, exactly as Unicode.xs does: BOM detection and big-endian fallback for the BOM-less UTF-16/UTF-32, surrogate pairs, the U+FFFD substitution, and the CHECK handling (croak, warn, leave or consume the source).

use Encode;
printf "%vX\n", encode('UTF-16LE', "hi");          # 68.0.69.0
print decode('UTF-16', "\xFE\xFF\0A\0B"), "\n";    # AB (the BOM says big-endian)
printf "%vX\n", encode('UTF-16', "\x{1F600}");     # FE.FF.D8.3D.DE.0: BOM, surrogate pair

The encodings are UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UCS-2BE and UCS-2LE; Encode loads this module the first time one of them is named. This is a native implementation of the XS half of Encode::Unicode 2.20.

Differences from upstream#

None.

Modules#

Functions#

Other Functions#

decode#

$obj->decode($octets [, $check]) - UTF-16/32 or UCS-2 octets to a character string.

encode#

$obj->encode($string [, $check]) - a character string to UTF-16/32 or UCS-2 octets.