# Revision history for Perl extension Encode.
#
-# $Id: Changes,v 1.66 2002/05/01 05:41:06 dankogai Exp dankogai $
+# $Id: Changes,v 1.67 2002/05/02 07:33:09 dankogai Exp $
#
-$Revision: 1.66 $ $Date: 2002/05/01 05:41:06 $
+$Revision: 1.67 $ $Date: 2002/05/02 07:33:09 $
+! Encode.xs
+ Error message now consistent w/ perlqq (\N{U+} -> \x{})
+ done in perl@16308 but Philip linted me further. Now the error
+ messages are macronized as ERR_ENCODE_NOMAP and ERR_DECODE_NOMAP
+! lib/Encode/Guess.pm
+ Sanity check for happier -w by Autrijus
+
+1.66 2002/05/01 05:41:06
! Encode.xs t/fallback.t
WARN_ON_ERR no longer assumes RETURN_ON_ERR so you can issue a warning
while fallback is in effect. This even came with a welcome side-effect
Typo fixes and improvements by jhi
Message-Id: <200204010201.FAA03564@alpha.hut.fi>, et al.
-1.11 $Date: 2002/05/01 05:41:06 $
+1.11 $Date: 2002/05/02 07:33:09 $
+ t/encoding.t
+ t/jperl.t
! MANIFEST
#
-# $Id: Encode.pm,v 1.66 2002/05/01 05:41:06 dankogai Exp dankogai $
+# $Id: Encode.pm,v 1.67 2002/05/02 07:33:34 dankogai Exp $
#
package Encode;
use strict;
-our $VERSION = do { my @r = (q$Revision: 1.66 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.67 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our $DEBUG = 0;
use XSLoader ();
XSLoader::load(__PACKAGE__, $VERSION);
/*
- $Id: Encode.xs,v 1.43 2002/05/01 05:41:06 dankogai Exp dankogai $
+ $Id: Encode.xs,v 1.44 2002/05/02 07:33:09 dankogai Exp $
*/
#define PERL_NO_GET_CONTEXT
}
+#define ERR_ENCODE_NOMAP "\"\\x{%04" UVxf "}\" does not map to %s"
+#define ERR_DECODE_NOMAP "%s \"\\x%02" UVXf "\" does not map to Unicode"
+
static SV *
encode_method(pTHX_ encode_t * enc, encpage_t * dir, SV * src,
int check)
utf8n_to_uvuni(s+slen, (SvCUR(src)-slen),
&clen, UTF8_ALLOW_ANY|UTF8_CHECK_ONLY);
if (check & ENCODE_DIE_ON_ERR) {
- Perl_croak(
- aTHX_ "\"\\x{%04" UVxf "}\" does not map to %s",
- (UV)ch, enc->name[0]);
+ Perl_croak(aTHX_ ERR_ENCODE_NOMAP,
+ (UV)ch, enc->name[0]);
return &PL_sv_undef; /* never reaches but be safe */
}
if (check & ENCODE_WARN_ON_ERR){
Perl_warner(aTHX_ packWARN(WARN_UTF8),
- "\"\\x{%" UVxf "}\" does not map to %s",
- (UV)ch, enc->name[0]);
+ ERR_ENCODE_NOMAP, (UV)ch, enc->name[0]);
}
if (check & ENCODE_RETURN_ON_ERR){
goto ENCODE_SET_SRC;
/* decoding */
else {
if (check & ENCODE_DIE_ON_ERR){
- Perl_croak(
- aTHX_ "%s \"\\x%02" UVXf
- "\" does not map to Unicode (%d)",
- (UV)enc->name[0], (U8)s[slen], code);
+ Perl_croak(aTHX_ ERR_DECODE_NOMAP,
+ (UV)enc->name[0], (U8)s[slen]);
return &PL_sv_undef; /* never reaches but be safe */
}
if (check & ENCODE_WARN_ON_ERR){
Perl_warner(
aTHX_ packWARN(WARN_UTF8),
- "%s \"\\x%02" UVXf
- "\" does not map to Unicode (%d)",
- (UV)enc->name[0], (U8)s[slen], code);
+ ERR_DECODE_NOMAP,
+ (UV)enc->name[0], (U8)s[slen]);
}
if (check & ENCODE_RETURN_ON_ERR){
goto ENCODE_SET_SRC;
use strict;
use Encode qw(:fallbacks find_encoding);
-our $VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
my $Canon = 'Guess';
our $DEBUG = 0;
my $class = shift;
my $obj = ref($class) ? $class : $Encode::Encoding{$Canon};
my $octet = shift;
+
+ # sanity check
+ return unless defined $octet and length $octet;
+
# cheat 0: utf8 flag;
Encode::is_utf8($octet) and return find_encoding('utf8');
# cheat 1: BOM
use Encode::Unicode;
my $BOM = unpack('n', $octet);
return find_encoding('UTF-16')
- if ($BOM == 0xFeFF or $BOM == 0xFFFe);
+ if (defined $BOM and ($BOM == 0xFeFF or $BOM == 0xFFFe));
$BOM = unpack('N', $octet);
return find_encoding('UTF-32')
- if ($BOM == 0xFeFF or $BOM == 0xFFFe0000);
+ if (defined $BOM and ($BOM == 0xFeFF or $BOM == 0xFFFe0000));
my %try = %{$obj->{Suspects}};
for my $c (@_){