Map(3pm) | User Contributed Perl Documentation | Map(3pm) |
Unicode::Map - maps charsets from and to utf16 unicode
$Map = new Unicode::Map("ISO-8859-1");
$utf16 =
$Map -> to_unicode
("Hello world!");
=> $utf16 == "\0H\0e\0l\0l\0o\0
\0w\0o\0r\0l\0d\0!"
$locale =
$Map -> from_unicode
($utf16);
=> $locale == "Hello world!"
A more detailed description below.
2do: short note about perl's Unicode perspectives.
This module converts strings from and to 2-byte Unicode UCS2 format. All mappings happen via 2 byte UTF16 encodings, not via 1 byte UTF8 encoding. To transform these use Unicode::String.
For historical reasons this module coexists with Unicode::Map8. Please use Unicode::Map8 unless you need to care for two byte character sets, e.g. chinese GB2312. Anyway, if you stick to the basic functionality (see documentation) you can use both modules equivalently.
Practically this module will disappear from earth sooner or later as Unicode mapping support needs somehow to get into perl's core. If you like to work on this field please don't hesitate contacting Gisle Aas!
This module can't deal directly with utf8. Use Unicode::String to convert utf8 to utf16 and vice versa.
Character mapping is according to the data of binary mapfiles in Unicode::Map hierarchy. Binary mapfiles can also be created with this module, enabling you to install own specific character sets. Refer to mkmapfile or file REGISTRY in the Unicode::Map hierarchy.
Probably these are the only methods you will need from this module. Their usage is compatible with Unicode::Map8.
Returns a new Map object for GB2312-80 encoding.
Creates a string in locale charset representation from utf16 encoded string $src.
Creates a string in utf16 representation from $src.
You can demand Unicode::Map to issue warnings at deprecated or incompatible usage with the constants WARN_DEFAULT, WARN_DEPRECATION or WARN_COMPATIBILITY. The latter both can be ored together.
Note: These methods are solely for the maintainance of Unicode::Map. Using any of these methods will lead to programs incompatible with Unicode::Map8.
Returns a list of alias names of character set $csid.
Returns the absolute path of binary character mapping for character set $csid according to REGISTRY file of Unicode::Map.
Returns a valid character set identifier $real_id, if $test_id is a valid character set name or alias name according to REGISTRY file of Unicode::Map.
Returns a list of all character set names defined in REGISTRY file.
Read a text mapping of style $style named $csid from filename $path. The mapping then can be saved to a file with method: write_binary_mapping. <$style> can be:
style description "unicode" A text mapping as of ftp://ftp.unicode.org/MAPPINGS/ "" Same as "unicode" "reverse" Similar to unicode, but both columns are switched "keld" A text mapping as of ftp://dkuug.dk/i18n/charmaps/
Returns the path of textual character mapping for character set $csid according to REGISTRY file of Unicode::Map.
Returns the style of textual character mapping for character set $csid according to REGISTRY file of Unicode::Map.
Stores a mapping that has been loaded via method read_text_mapping in file $path.
Some functionality is no longer promoted.
Structure of binary Mapfiles
Unicode character mapping tables have sequences of sequential key and sequential value codes. This property is used to crunch the maps easily. n (0<n<256) sequential characters are represented as a bytecount n and the first character code key_start. For these subsequences the according value sequences are crunched together, also. The value 0 is used to start an extended information block (that is just partially implemented, though).
One could think of two ways to make a binary mapfile. First method would be first to write a list of all key codes, and then to write a list of all value codes. Second method, used here, appends to all partial key code lists the according crunched value code lists. This makes value codes a little bit closer to key codes.
Note: the file format is still in a very liquid state. Neither rely on that it will stay as this, nor that the description is bugless, nor that all features are implemented.
STRUCTURE:
offset structure value 0x00 word 0x27b8 (magic) 0x02 @(<extended> || <submapping>)
The mapfile ends with extended mode <end> in main stream.
0x00 byte != 0 charsize1 (bits) 0x01 byte n1 number of chars for one entry 0x02 byte charsize2 (bits) 0x03 byte n2 number of chars for one entry 0x04 @(<extended> || <key_seq> || <key_val_seq) bs1=int((charsize1+7)/8), bs2=int((charsize2+7)/8)
One submapping ends when <mapend> entry occurs.
0x00 size=0|1|2|4 n, number of sequential characters size bs1 key1 +bs1 bs2 value1 +bs2 bs1 key2 +bs1 bs2 value2 ...
key_val_seq ends, if either file ends (n = infinite mode) or n pairs are read.
0x00 byte n, number of sequential characters 0x01 bs1 key_start, first character of sequence 1+bs1 @(<extended> || <val_seq>)
A key sequence starts with a byte count telling how long the sequence is. It is followed by the key start code. After this comes a list of value sequences. The list of value sequences ends, if sum(m) equals n.
0x00 byte m, number of sequential characters 0x01 bs2 val_start, first character of sequence
0x00 byte 0 0x01 byte ftype 0x02 byte fsize, size of following structure 0x03 fsize bytes something
For future extensions or private use one can insert here 1..255 byte long streams. ftype can have values 30..255, values 0..29 are reserved. Modi are not fully defined now and could change. They will be explained later.
Martin Schwartz <martin@nacho.de>
2022-10-19 | perl v5.36.0 |