diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-07-10 03:50:18 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-07-10 03:50:18 +0000 |
commit | 8e86646e958d6dc7566f90f497756b5c18800b82 (patch) | |
tree | c054bae36bf8d9d445d340c671c9dcfeb2f0225c /ext | |
parent | 07d121d92015bba46886a5db08466e60f4112a7c (diff) | |
download | perl-8e86646e958d6dc7566f90f497756b5c18800b82.tar.gz |
Add a test for for PerlIO ":encoding(...)" layer.
p4raw-id: //depot/perl@11249
Diffstat (limited to 'ext')
-rw-r--r-- | ext/Encode/Encode.pm | 10 | ||||
-rw-r--r-- | ext/PerlIO/t/encoding.t | 49 |
2 files changed, 57 insertions, 2 deletions
diff --git a/ext/Encode/Encode.pm b/ext/Encode/Encode.pm index 4e55f46286..b84623a38c 100644 --- a/ext/Encode/Encode.pm +++ b/ext/Encode/Encode.pm @@ -739,9 +739,15 @@ If Perl is configured to use the new 'perlio' IO system then C<Encode> provides a "layer" (See L<perliol>) which can transform data as it is read or written. +Here is how the blind poet would modernise the encoding: + use Encode; - open(my $ilyad,'>:encoding(iso-8859-7)','ilyad.greek'); - print $ilyad @epic; + open(my $iliad,'<:encoding(iso-8859-7)','iliad.greek'); + open(my $utf8,'>:utf8','iliad.utf8'); + my @epic = <$iliad>; + print $utf8 @epic; + close($utf8); + close($illiad); In addition the new IO system can also be configured to read/write UTF-8 encoded characters (as noted above this is efficient): diff --git a/ext/PerlIO/t/encoding.t b/ext/PerlIO/t/encoding.t new file mode 100644 index 0000000000..bfae3ed7b0 --- /dev/null +++ b/ext/PerlIO/t/encoding.t @@ -0,0 +1,49 @@ +my $grk = "grk$$"; +my $utf = "utf$$"; + +if (open(GRK, ">$grk")) { + # alpha beta gamma in ISO 8859-7 + print GRK "\xe1\xe2\xe3"; + close GRK; +} + +{ + use Encode; + open(my $i,'<:encoding(iso-8859-7)',$grk); + print "ok 1\n"; + open(my $o,'>:utf8',$utf); + print "ok 2\n"; + print $o readline($i); + print "ok 3\n"; + close($o); + close($i); +} + +if (open(UTF, "<$utf")) { + # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3) + print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3"; + print "ok 4\n"; + close $grk; +} + +{ + use Encode; + open(my $i,'<:utf8',$utf); + print "ok 5\n"; + open(my $o,'>:encoding(iso-8859-7)',$grk); + print "ok 6\n"; + print $o readline($i); + print "ok 7\n"; + close($o); + close($i); +} + +if (open(GRK, "<$grk")) { + print "not " unless <GRK> eq "\xe1\xe2\xe3"; + print "ok 8\n"; + close $grk; +} + +END { + unlink($grk, $utf); +} |