diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-03-27 19:38:50 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-03-27 19:38:50 +0000 |
commit | 5ad8ef521b3ffc4e6bbbb9941bc4940d442b56b2 (patch) | |
tree | 41c823d39662a2d89f77c1fbfa9e0ce5dff5ffab /ext | |
parent | 423473382362f0c78b47eff19336aafe6728495e (diff) | |
download | perl-5ad8ef521b3ffc4e6bbbb9941bc4940d442b56b2.tar.gz |
Various EBCDIC fixes:
- major revelation that swash code is encoding aware,
(or thought it was) - now it is ;-)
- With that out of the way fix a slab of tr/// cases.
- Fix Encode 'Unicode' to be true Unicode so tests pass.
- As anticipated Base64.xs needed tweaks.
- Until tr/// works right avoid old_encode64 in MIME tests.
p4raw-id: //depot/perlio@9384
Diffstat (limited to 'ext')
-rw-r--r-- | ext/Encode/Encode.pm | 39 | ||||
-rw-r--r-- | ext/MIME/Base64/Base64.xs | 24 |
2 files changed, 48 insertions, 15 deletions
diff --git a/ext/Encode/Encode.pm b/ext/Encode/Encode.pm index 650180647b..fde3891b6f 100644 --- a/ext/Encode/Encode.pm +++ b/ext/Encode/Encode.pm @@ -60,6 +60,7 @@ sub findAlias my $alias = $alias[$i]; my $val = $alias[$i+1]; my $new; + if (ref($alias) eq 'Regexp' && $_ =~ $alias) { $new = eval $val; @@ -68,7 +69,7 @@ sub findAlias { $new = &{$alias}($val) } - elsif (lc($_) eq $alias) + elsif (lc($_) eq lc($alias)) { $new = $val; } @@ -222,13 +223,15 @@ sub new_sequence { return $_[0] } package Encode::XS; use base 'Encode::Encoding'; -package Encode::Unicode; +package Encode::Internal; use base 'Encode::Encoding'; # Dummy package that provides the encode interface but leaves data # as UTF-X encoded. It is here so that from_to() works. -__PACKAGE__->Define('Unicode'); +__PACKAGE__->Define('Internal'); + +Encode::define_alias( 'Unicode' => 'Internal' ) if ord('A') == 65; sub decode { @@ -240,6 +243,36 @@ sub decode *encode = \&decode; +package Encoding::Unicode; +use base 'Encode::Encoding'; + +__PACKAGE__->Define('Unicode') unless ord('A') == 65; + +sub decode +{ + my ($obj,$str,$chk) = @_; + my $res = ''; + for (my $i = 0; $i < length($str); $i++) + { + $res .= chr(utf8::unicode_to_native(ord(substr($str,$i,1)))); + } + $_[1] = '' if $chk; + return $res; +} + +sub encode +{ + my ($obj,$str,$chk) = @_; + my $res = ''; + for (my $i = 0; $i < length($str); $i++) + { + $res .= chr(utf8::native_to_unicode(ord(substr($str,$i,1)))); + } + $_[1] = '' if $chk; + return $res; +} + + package Encode::utf8; use base 'Encode::Encoding'; # package to allow long-hand diff --git a/ext/MIME/Base64/Base64.xs b/ext/MIME/Base64/Base64.xs index 118d170823..f77ba14eab 100644 --- a/ext/MIME/Base64/Base64.xs +++ b/ext/MIME/Base64/Base64.xs @@ -11,15 +11,15 @@ metamail, which comes with this message: Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore) - Permission to use, copy, modify, and distribute this material - for any purpose and without fee is hereby granted, provided - that the above copyright notice and this permission notice - appear in all copies, and that the name of Bellcore not be - used in advertising or publicity pertaining to this - material without the specific, prior written permission - of an authorized representative of Bellcore. BELLCORE - MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY - OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS", + Permission to use, copy, modify, and distribute this material + for any purpose and without fee is hereby granted, provided + that the above copyright notice and this permission notice + appear in all copies, and that the name of Bellcore not be + used in advertising or publicity pertaining to this + material without the specific, prior written permission + of an authorized representative of Bellcore. BELLCORE + MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY + OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. */ @@ -160,7 +160,7 @@ decode_base64(sv) PREINIT: STRLEN len; - register unsigned char *str = (unsigned char*)SvPV(sv, len); + register unsigned char *str = (unsigned char*)SvPVbyte(sv, len); unsigned char const* end = str + len; char *r; unsigned char c[4]; @@ -177,7 +177,7 @@ decode_base64(sv) while (str < end) { int i = 0; do { - unsigned char uc = index_64[*str++]; + unsigned char uc = index_64[NATIVE_TO_ASCII(*str++)]; if (uc != INVALID) c[i++] = uc; @@ -192,7 +192,7 @@ decode_base64(sv) break; } } while (i < 4); - + if (c[0] == EQ || c[1] == EQ) { if (PL_dowarn) warn("Premature padding of base64 data"); break; |