package Encode::Alias;
use strict;
use Encode;
-our $VERSION = do { my @r = (q$Revision: 1.0 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.27 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our $DEBUG = 0;
require Exporter;
local $_ = shift;
unless (exists $Alias{$_})
{
+ $Alias{$_} = undef; # Recursion guard
for (my $i=0; $i < @Alias; $i += 2)
{
my $alias = $Alias[$i];
sub init_aliases
{
undef_aliases();
- # 'C' => 'US-ascii' so you can feed default locale directly.
- define_alias('C' => 'US-ascii');
+
+ # Try all-lower-case version should all else fails
+ define_alias( qr/^(.*)$/ => '"\L$1"' );
+
+ # UTF/UCS stuff
+ define_alias( qr/^UCS-?2-?LE$/i => '"UCS-2LE"' );
+ define_alias( qr/^UCS-?2-?(BE)?$/i => '"UCS-2BE"',
+ qr/^iso-10646-1$/i => '"UCS-2BE"' );
+ define_alias( qr/^UTF(16|32)-?BE$/i => '"UTF-$1BE"',
+ qr/^UTF(16|32)-?LE$/i => '"UTF-$1LE"',
+ qr/^UTF(16|32)$/i => '"UTF-$1"',
+ );
+ # ASCII
+ define_alias(qr/^(?:US-?)ascii$/i => '"ascii"');
+ define_alias('C' => 'ascii');
# Allow variants of iso-8859-1 etc.
define_alias( qr/\biso[-_]?(\d+)[-_](\d+)$/i => '"iso-$1-$2"' );
define_alias( qr/\b(?:ibm|ms|windows)[-_]?(\d\d\d\d?)$/i => '"cp$1"');
# Sometimes seen with a leading zero.
- define_alias( qr/\bcp037\b/i => '"cp37"');
-
- # Ououououou.
- define_alias( qr/\bmacRomanian$/i => '"macRumanian"');
-
-# Standardize on the dashed versions.
+ # define_alias( qr/\bcp037\b/i => '"cp37"');
+
+ # Mac Mappings
+ # predefined in *.ucm; unneeded
+ # define_alias( qr/\bmacIcelandic$/i => '"macIceland"');
+ define_alias( qr/^mac_(.*)$/i => '"mac$1"');
+ # Ououououou. gone. They are differente!
+ # define_alias( qr/\bmacRomanian$/i => '"macRumanian"');
+
+ # Standardize on the dashed versions.
# define_alias( qr/\butf8$/i => 'utf-8' );
define_alias( qr/\bkoi8r$/i => 'koi8-r' );
define_alias( qr/\bkoi8u$/i => 'koi8-u' );
define_alias( qr/\bbig-?5$/i => '"big5"' );
define_alias( qr/\bbig5-hk(?:scs)?$/i => '"big5-hkscs"' );
}
-
+ # utf8 is blessed :)
+ define_alias( qr/^UTF-8$/i => '"utf8"',);
# At last, Map white space and _ to '-'
define_alias( qr/^(\S+)[\s_]+(.*)$/i => '"$1-$2"' );
}
=head1 NAME
-Encode::Alias - alias defintions to encodings
+Encode::Alias - alias definitions to encodings
=head1 SYNOPSIS
=head1 DESCRIPTION
-Allows newName to be used as am alias for ENCODING. ENCODING may be
-either the name of an encoding or and encoding object (as described in L<Encode>).
+Allows newName to be used as an alias for ENCODING. ENCODING may be
+either the name of an encoding or an encoding object (as described
+in L<Encode>).
Currently I<newName> can be specified in the following ways:
define_alias( qr/^iso8859-(\d+)$/i => '"iso-8859-$1"' );
In this case if I<ENCODING> is not a reference it is C<eval>-ed to
-allow C<$1> etc. to be subsituted. The example is one way to names as
-used in X11 font names to alias the MIME names for the iso-8859-*
-family. Note the double quote inside the single quote.
+allow C<$1> etc. to be substituted. The example is one way to alias
+names as used in X11 fonts to the MIME names for the iso-8859-*
+family. Note the double quote inside the single quote.
-If you are using regex here, you have to do so or it won't work in
-this case. Also not regex is tricky even for the experienced. Use it
-with caution.
+If you are using a regex here, you have to use the quotes as shown or
+it won't work. Also note that regex handling is tricky even for the
+experienced. Use it with caution.
=item As a code reference, e.g.:
define_alias( sub { return /^iso8859-(\d+)$/i ? "iso-8859-$1" : undef } , '');
+
In this case C<$_> will be set to the name that is being looked up and
I<ENCODING> is passed to the sub as its first argument. The example
-is another way to names as used in X11 font names to alias the MIME
-names for the iso-8859-* family.
+is another way to alias names as used in X11 fonts to the MIME names
+for the iso-8859-* family.
=back
=head2 Alias overloading
-You can override predefined aliases by simply applying define_alias().
+You can override predefined aliases by simply applying define_alias().
New alias is always evaluated first and when neccessary define_alias()
flushes internal cache to make new definition available.