[Templates-cvs] cvs commit: Template2/lib/Template Provider.pm

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/02/01 08:36:09

  Modified:    lib/Template Provider.pm
  Log:
  * added Encoding option
  
  Revision  Changes    Path
  2.87      +18 -13    Template2/lib/Template/Provider.pm
  
  Index: Provider.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template/Provider.pm,v
  retrieving revision 2.86
  retrieving revision 2.87
  diff -u -r2.86 -r2.87
  --- Provider.pm	2006/01/30 20:04:54	2.86
  +++ Provider.pm	2006/02/01 08:36:09	2.87
  @@ -27,7 +27,7 @@
   #
   #----------------------------------------------------------------------------
   #
  -# $Id: Provider.pm,v 2.86 2006/01/30 20:04:54 abw Exp $
  +# $Id: Provider.pm,v 2.87 2006/02/01 08:36:09 abw Exp $
   #
   #============================================================================
   
  @@ -49,7 +49,7 @@
   use constant NEXT   => 4;
   use constant STAT   => 5;
   
  -our $VERSION = sprintf("%d.%02d", q$Revision: 2.86 $ =~ /(\d+)\.(\d+)/);
  +our $VERSION = sprintf("%d.%02d", q$Revision: 2.87 $ =~ /(\d+)\.(\d+)/);
   our $DEBUG   = 0 unless defined $DEBUG;
   our $ERROR   = '';
   
  @@ -401,9 +401,10 @@
       $self->{ RELATIVE     } = $params->{ RELATIVE } || 0;
       $self->{ TOLERANT     } = $params->{ TOLERANT } || 0;
       $self->{ DOCUMENT     } = $params->{ DOCUMENT } || $DOCUMENT;
  -    $self->{ PARSER       } = $params->{ PARSER };
  -    $self->{ DEFAULT      } = $params->{ DEFAULT };
  -#   $self->{ PREFIX       } = $params->{ PREFIX };
  +    $self->{ PARSER       } = $params->{ PARSER   };
  +    $self->{ DEFAULT      } = $params->{ DEFAULT  };
  +    $self->{ ENCODING     } = $params->{ ENCODING };
  +#   $self->{ PREFIX       } = $params->{ PREFIX   };
       $self->{ PARAMS       } = $params;
   
       # look for user-provided UNICODE parameter or use default from package var
  @@ -1001,16 +1002,20 @@
   #------------------------------------------------------------------------
   
   
  -sub _decode_unicode
  -{
  -    use bytes;
  -
  +sub _decode_unicode {
       my $self   = shift;
       my $string = shift;
   
  +    use bytes;
  +    require Encode;
  +    
  +    return $string if Encode::is_utf8( $string );
  +    
       # try all the BOMs in order looking for one (order is important
       # 32bit BOMs look like 16bit BOMs)
  -    my $count = 0;
  +
  +    my $count  = 0;
  +
       while ($count < @{ $boms }) {
           my $enc = $boms->[$count++];
           my $bom = $boms->[$count++];
  @@ -1018,13 +1023,13 @@
           # does the string start with the bom?
           if ($bom eq substr($string, 0, length($bom))) {
               # decode it and hand it back
  -            require Encode;
               return Encode::decode($enc, substr($string, length($bom)), 1);
           }
       }
   
  -    # no boms matched so it must be a non unicode string which we return as is
  -    return $string;
  +    return $self->{ ENCODING }
  +        ? Encode::decode( $self->{ ENCODING }, $string )
  +        : $string;
   }