From: Graham B. <gb...@us...> - 2003-05-06 11:07:23
|
Update of /cvsroot/perl-ldap/asn/lib/Convert/ASN1 In directory sc8-pr-cvs1:/tmp/cvs-serv6983/lib/Convert/ASN1 Modified Files: _decode.pm _encode.pm Log Message: utf8 support for perl >= 5.8 Index: _decode.pm =================================================================== RCS file: /cvsroot/perl-ldap/asn/lib/Convert/ASN1/_decode.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- _decode.pm 25 Mar 2002 09:06:16 -0000 1.15 +++ _decode.pm 6 May 2003 11:07:19 -0000 1.16 @@ -7,8 +7,10 @@ # $Id$ BEGIN { - local $SIG{__DIE__}; - eval { require bytes } and 'bytes'->import + unless (CHECK_UTF8) { + local $SIG{__DIE__}; + eval { require bytes } and 'bytes'->import + } } # These are the subs that do the decode, they are called with @@ -536,12 +538,20 @@ # $optn, $op, $stash, $var, $buf, $pos, $len BEGIN { - local $SIG{__DIE__}; - eval { require bytes } and 'bytes'->unimport; - eval { require utf8 } and 'utf8'->import; + unless (CHECK_UTF8) { + local $SIG{__DIE__}; + eval { require bytes } and 'bytes'->unimport; + eval { require utf8 } and 'utf8'->import; + } + } + + if (CHECK_UTF8) { + $_[3] = Encode::decode('utf8', substr($_[4],$_[5],$_[6])); + } + else { + $_[3] = (substr($_[4],$_[5],$_[6]) =~ /(.*)/s)[0]; } - $_[3] = (substr($_[4],$_[5],$_[6]) =~ /(.*)/s)[0]; 1; } Index: _encode.pm =================================================================== RCS file: /cvsroot/perl-ldap/asn/lib/Convert/ASN1/_encode.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- _encode.pm 19 Aug 2002 23:51:38 -0000 1.16 +++ _encode.pm 6 May 2003 11:07:20 -0000 1.17 @@ -7,8 +7,10 @@ # $Id$ BEGIN { - local $SIG{__DIE__}; - eval { require bytes } and 'bytes'->import + unless (CHECK_UTF8) { + local $SIG{__DIE__}; + eval { require bytes } and 'bytes'->import + } } # These are the subs which do the encoding, they are called with @@ -127,8 +129,15 @@ # 0 1 2 3 4 5 6 # $optn, $op, $stash, $var, $buf, $loop, $path - $_[4] .= asn_encode_length(length $_[3]); - $_[4] .= $_[3]; + if (CHECK_UTF8 and Encode::is_utf8($_[3])) { + utf8::encode(my $tmp = $_[3]); + $_[4] .= asn_encode_length(length $tmp); + $_[4] .= $tmp; + } + else { + $_[4] .= asn_encode_length(length $_[3]); + $_[4] .= $_[3]; + } } @@ -329,8 +338,17 @@ # 0 1 2 3 4 5 6 # $optn, $op, $stash, $var, $buf, $loop, $path - $_[4] .= asn_encode_length(length $_[3]); - $_[4] .= $_[3]; + if (CHECK_UTF8) { + my $tmp = $_[3]; + utf8::upgrade($tmp) unless Encode::is_utf8($tmp); + utf8::encode($tmp); + $_[4] .= asn_encode_length(length $tmp); + $_[4] .= $tmp; + } + else { + $_[4] .= asn_encode_length(length $_[3]); + $_[4] .= $_[3]; + } } |