package Encode;
use strict;
-our $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.20 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our $DEBUG = 0;
require DynaLoader;
# Make a %Encoding package variable to allow a certain amount of cheating
our %Encoding;
-
-our %ExtModule =
- (
- viscii => 'Encode/Byte.pm',
- 'koi8-r' => 'Encode/Byte.pm',
- cp1047 => 'Encode/EBCDIC.pm',
- cp37 => 'Encode/EBCDIC.pm',
- 'posix-bc' => 'Encode/EBCDIC.pm',
- symbol => 'Encode/Symbol.pm',
- dingbats => 'Encode/Symbol.pm',
- );
+our %ExtModule;
+
+my @codepages = qw(
+ 37 424 437 500 737 775 850 852 855
+ 856 857 860 861 862 863 864 865 866
+ 869 874 875 932 936 949 950 1006 1026
+ 1047 1250 1251 1252 1253 1254 1255 1256 1257
+ 1258
+ );
+
+my @macintosh = qw(
+ CentralEurRoman Croatian Cyrillic Greek
+ Iceland Roman Rumanian Sami
+ Thai Turkish Ukrainian
+ );
for my $k (2..11,13..16){
$ExtModule{"iso-8859-$k"} = 'Encode/Byte.pm';
}
-for my $k (1250..1258){
+for my $k (@codepages){
$ExtModule{"cp$k"} = 'Encode/Byte.pm';
}
+for my $k (@macintosh)
+{
+ $ExtModule{"mac$k"} = 'Encode/Byte.pm';
+}
+
+%ExtModule =
+ (%ExtModule,
+ 'koi8-r' => 'Encode/Byte.pm',
+ 'posix-bc' => 'Encode/EBCDIC.pm',
+ cp037 => 'Encode/EBCDIC.pm',
+ cp1026 => 'Encode/EBCDIC.pm',
+ cp1047 => 'Encode/EBCDIC.pm',
+ cp500 => 'Encode/EBCDIC.pm',
+ cp875 => 'Encode/EBCDIC.pm',
+ dingbats => 'Encode/Symbol.pm',
+ macDingbats => 'Encode/Symbol.pm',
+ macSymbol => 'Encode/Symbol.pm',
+ symbol => 'Encode/Symbol.pm',
+ viscii => 'Encode/Byte.pm',
+);
+
unless ($ON_EBCDIC) { # CJK added to autoload unless EBCDIC env
-%ExtModule =(
- %ExtModule,
+%ExtModule =(%ExtModule,
'euc-cn' => 'Encode/CN.pm',
gb2312 => 'Encode/CN.pm',
gb12345 => 'Encode/CN.pm',
'iso-2022-jp-1' => 'Encode/JP.pm',
'7bit-jis' => 'Encode/JP.pm',
shiftjis => 'Encode/JP.pm',
- macjapan => 'Encode/JP.pm',
+ macJapanese => 'Encode/JP.pm',
cp932 => 'Encode/JP.pm',
'euc-kr' => 'Encode/KR.pm',
ksc5601 => 'Encode/KR.pm',
+ macKorean => 'Encode/KR.pm',
cp949 => 'Encode/KR.pm',
big5 => 'Encode/TW.pm',
'big5-hkscs' => 'Encode/TW.pm',
);
}
-for my $k (qw(centeuro croatian cyrillic dingbats greek
- iceland roman rumanian sami
- thai turkish ukraine))
-{
- $ExtModule{"mac$k"} = 'Encode/Byte.pm';
-}
+
sub encodings
croak("Unknown encoding '$to'") unless defined $t;
my $uni = $f->decode($string,$check);
return undef if ($check && length($string));
- $string = $t->encode($uni,$check);
+ $string = $t->encode($uni,$check);
return undef if ($check && length($uni));
- return length($_[0] = $string);
+ return defined($_[0] = $string) ? length($string) : undef ;
}
sub encode_utf8
$utf8 = decode("iso-8859-1", $latin1);
-=item from_to($string, FROM_ENCODING, TO_ENCODING[, CHECK])
+=item [$length =] from_to($string, FROM_ENCODING, TO_ENCODING[, CHECK])
Convert B<in-place> the data between two encodings. How did the data
in $string originally get to be in FROM_ENCODING? Either using
Note that because the conversion happens in place, the data to be
converted cannot be a string constant, it must be a scalar variable.
+from_to() return the length of the converted string on success, undef
+otherwise.
+
=back
=head2 Listing available encodings
use Encode::Alias;
define_alias(newName => ENCODING);
-After that, newName can be to be used as am alias for ENCODING.
-ENCODING may be either the name of an encoding or and I<encoding
-object>
+After that, newName can be used as an alias for ENCODING.
+ENCODING may be either the name of an encoding or an I<encoding
+ object>
See L<Encode::Alias> on details.