Upgrade to Encode 2.00.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode.pm
index 4959b5f..62be76e 100644 (file)
@@ -1,10 +1,10 @@
 #
-# $Id: Encode.pm,v 1.95 2003/05/21 08:40:59 dankogai Exp $
+# $Id: Encode.pm,v 2.0 2004/05/16 20:55:15 dankogai Exp $
 #
 package Encode;
 use strict;
-our $VERSION = do { my @r = (q$Revision: 1.95 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
-our $DEBUG = 0;
+our $VERSION = do { my @r = (q$Revision: 2.0 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+sub DEBUG () { 0 }
 use XSLoader ();
 XSLoader::load(__PACKAGE__, $VERSION);
 
@@ -60,7 +60,7 @@ sub encodings
     }else{
        %enc = %Encoding;
        for my $mod (map {m/::/o ? $_ : "Encode::$_" } @_){
-           $DEBUG and warn $mod;
+           DEBUG and warn $mod;
            for my $enc (keys %ExtModule){
                $ExtModule{$enc} eq $mod and $enc{$enc} = $mod;
            }
@@ -147,7 +147,7 @@ sub encode($$;$)
        Carp::croak("Unknown encoding '$name'");
     }
     my $octets = $enc->encode($string,$check);
-    return undef if ($check && length($string));
+    $_[1] = $string if $check;
     return $octets;
 }
 
@@ -195,11 +195,15 @@ sub encode_utf8($)
     return $str;
 }
 
-sub decode_utf8($)
+sub decode_utf8($;$)
 {
-    my ($str) = @_;
-    return undef unless utf8::decode($str);
-    return $str;
+    my ($str, $check) = @_;
+    if ($check){
+       return decode("utf8", $str, $check);
+    }else{
+       return undef unless utf8::decode($str);
+       return $str;
+    }
 }
 
 predefine_encodings(1);
@@ -258,11 +262,11 @@ sub predefine_encodings{
        push @Encode::utf8::ISA, 'Encode::Encoding';
        # 
        if ($use_xs){
-           $DEBUG and warn __PACKAGE__, " XS on";
+           Encode::DEBUG and warn __PACKAGE__, " XS on";
            *decode = \&decode_xs;
            *encode = \&encode_xs;
        }else{
-           $DEBUG and warn __PACKAGE__, " XS off";
+           Encode::DEBUG and warn __PACKAGE__, " XS off";
            *decode = sub{
                my ($obj,$octets,$chk) = @_;
                my $str = Encode::decode_utf8($octets);
@@ -739,6 +743,8 @@ implementation.  As such, they are efficient but may change.
 If CHECK is true, also checks the data in STRING for being well-formed
 UTF-8.  Returns true if successful, false otherwise.
 
+As of perl 5.8.1, L<utf8> also has utf8::is_utf8().
+
 =item _utf8_on(STRING)
 
 [INTERNAL] Turns on the UTF-8 flag in STRING.  The data in STRING is