From b56b320b5e2515160073fa1b469514002688fe11 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 5 Apr 2016 22:27:26 +0000 Subject: tlperl 5.22.1 from siep git-svn-id: svn://tug.org/texlive/trunk@40252 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/tlperl/lib/Encode.pm | 44 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'Master/tlpkg/tlperl/lib/Encode.pm') diff --git a/Master/tlpkg/tlperl/lib/Encode.pm b/Master/tlpkg/tlperl/lib/Encode.pm index 5d477f6bdec..3bb10970de6 100644 --- a/Master/tlpkg/tlperl/lib/Encode.pm +++ b/Master/tlpkg/tlperl/lib/Encode.pm @@ -1,10 +1,10 @@ # -# $Id: Encode.pm,v 2.60 2014/04/29 16:26:49 dankogai Exp dankogai $ +# $Id: Encode.pm,v 2.72 2015/03/14 02:43:24 dankogai Exp $ # package Encode; use strict; use warnings; -our $VERSION = sprintf "%d.%02d", q$Revision: 2.60_01 $ =~ /(\d+)/g; +our $VERSION = sprintf "%d.%02d", q$Revision: 2.72 $ =~ /(\d+)/g; use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG}; use XSLoader (); XSLoader::load( __PACKAGE__, $VERSION ); @@ -156,7 +156,20 @@ sub encode($$;$) { require Carp; Carp::croak("Unknown encoding '$name'"); } - my $octets = $enc->encode( $string, $check ); + # For Unicode, warnings need to be caught and re-issued at this level + # so that callers can disable utf8 warnings lexically. + my $octets; + if ( ref($enc) eq 'Encode::Unicode' ) { + my $warn = ''; + { + local $SIG{__WARN__} = sub { $warn = shift }; + $octets = $enc->encode( $string, $check ); + } + warnings::warnif('utf8', $warn) if length $warn; + } + else { + $octets = $enc->encode( $string, $check ); + } $_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() ); return $octets; } @@ -172,7 +185,20 @@ sub decode($$;$) { require Carp; Carp::croak("Unknown encoding '$name'"); } - my $string = $enc->decode( $octets, $check ); + # For Unicode, warnings need to be caught and re-issued at this level + # so that callers can disable utf8 warnings lexically. + my $string; + if ( ref($enc) eq 'Encode::Unicode' ) { + my $warn = ''; + { + local $SIG{__WARN__} = sub { $warn = shift }; + $string = $enc->decode( $octets, $check ); + } + warnings::warnif('utf8', $warn) if length $warn; + } + else { + $string = $enc->decode( $octets, $check ); + } $_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() ); return $string; } @@ -457,7 +483,7 @@ If the $string is C, then C is returned. This function returns the string that results from decoding the scalar value I, assumed to be a sequence of octets in I, into -Perl's internal form. The returns the resulting string. As with encode(), +Perl's internal form. As with encode(), I can be either a canonical name or an alias. For encoding names and aliases, see L; for I, see L. @@ -547,7 +573,7 @@ Also note that: from_to($octets, $from, $to, $check); -is equivalent t:o +is equivalent to: $octets = encode($to, decode($from, $octets), $check); @@ -674,7 +700,7 @@ In the first version above, you let the appropriate encoding layer handle the conversion. In the second, you explicitly translate from one encoding to the other. -Unfortunately, it may be that encodings are C-savvy. You can check +Unfortunately, it may be that encodings are not C-savvy. You can check to see whether your encoding is supported by C by invoking the C method on it: @@ -810,7 +836,7 @@ Acts like C but U+I is used instead of C<\x{I}>. Even the fallback for C must return octets, which are then decoded with the character encoding that C accepts. So for -example if you wish to decode octests as UTF-8, and use ISO-8859-15 as +example if you wish to decode octets as UTF-8, and use ISO-8859-15 as a fallback for bytes that are not valid UTF-8, you could write $str = decode 'UTF-8', $octets, sub { @@ -1029,7 +1055,7 @@ who submitted code to the project. =head1 COPYRIGHT -Copyright 2002-2013 Dan Kogai I<< >>. +Copyright 2002-2014 Dan Kogai I<< >>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -- cgit v1.2.3