UC" /> UC" />
enc2xs -[options] enc2xs -M ModName mapfiles... enc2xs -C
$ ls -F my.ucm
$ enc2xs -M My my.ucm generating Makefile.PL generating My.pm generating README generating Changes
Now take a look at your current directory. It should look like this.
$ ls -F Makefile.PL My.pm my.ucm t/
The following files were created.
Makefile.PL - MakeMaker script My.pm - Encode submodule t/My.t - test file
$ mkdir Encode $ mv *.ucm Encode $ enc2xs -M My Encode/*ucm
$ perl Makefile.PL Writing Makefile for Encode::My
$ make cp My.pm blib/lib/Encode/My.pm /usr/local/bin/perl /usr/local/bin/enc2xs -Q -O \ -o encode_t.c -f encode_t.fnm Reading myascii (myascii) Writing compiled form 128 bytes in string tables 384 bytes (75%) saved spotting duplicates 1 bytes (0.775%) saved using substrings .... chmod 644 blib/arch/auto/Encode/My/My.bs $
The time it takes varies depending on how fast your machine is and how large your encoding is. Unless you are working on something big like euc-tw, it won't take too long.
$ make test PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib \ -e 'use Test::Harness qw(&runtests $verbose); \ $verbose=0; runtests @ARGV;' t/*.t t/My....ok All tests successful. Files=1, Tests=2, 0 wallclock secs ( 0.09 cusr + 0.01 csys = 0.09 CPU)
to update Encode::ConfigLocal, a module that controls local settings. After that, ``use Encode;'' is enough to load your encodings on demand.
A UCM file looks like this.
# # Comments # <code_set_name> "US-ascii" # Required <code_set_alias> "ascii" # Optional <mb_cur_min> 1 # Required; usually 1 <mb_cur_max> 1 # Max. # of bytes/char <subchar> \x3F # Substitution char # CHARMAP <U0000> \x00 |0 # <control> <U0001> \x01 |0 # <control> <U0002> \x02 |0 # <control> .... <U007C> \x7C |0 # VERTICAL LINE <U007D> \x7D |0 # RIGHT CURLY BRACKET <U007E> \x7E |0 # TILDE <U007F> \x7F |0 # <control> END CHARMAP
Most of the keywords are self-explanatory. subchar means substitution character, not subcharacter. When you decode a Unicode sequence to this encoding but no matching character is found, the byte sequence defined here will be used. For most cases, the value here is \x3F; in ASCII, this is a question mark.
<UXXXX> \xXX.. |0 # comment ^ ^ ^ | | +- Fallback flag | +-------- Encoded byte sequence +-------------- Unicode Character ID in hex
The format is roughly the same as a header section except for the fallback flag: | followed by 0..3. The meaning of the possible values is as follows:
When you are manually creating a UCM file, you should copy ascii.ucm or an existing encoding which is close to yours, rather than write your own from scratch.
When you do so, make sure you leave at least U0000 to U0020 as is, unless your environment is EBCDIC.
CAVEAT: not all features in UCM are implemented. For example, icu:state is not used. Because of that, you need to write a perl module if you want to support algorithmical encodings, notably the ISO-2022 series. Such modules include Encode::JP::2022_JP, Encode::KR::2022_KR, and Encode::TW::HZ.
Here is an example from big5-eten.
<U2550> \xF9\xF9 |0 <U2550> \xA2\xA4 |3
Internally Encoding -> Unicode and Unicode -> Encoding Map looks like this;
E to U U to E -------------------------------------- \xF9\xF9 => U2550 U2550 => \xF9\xF9 \xA2\xA4 => U2550
So it is round-trip safe for \xF9\xF9. But if the line above is upside down, here is what happens.
E to U U to E -------------------------------------- \xA2\xA4 => U2550 U2550 => \xF9\xF9 (\xF9\xF9 => U2550 is now overwritten!)
The Encode package comes with ucmlint, a crude but sufficient utility to check the integrity of a UCM file. Check under the Encode/bin directory for this.
When in doubt, you can use ucmsort, yet another utility under Encode/bin directory.