Revision 112
- Date:
- 2011/08/15 14:19:22
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/core/lib/Contenido/Parser.pm
12 12 use Contenido::File::Scheme::FILE; 13 13 use Contenido::Parser::Util; 14 14 15 sub new { 16 my ($proto) = @_; 17 my $class = ref($proto) || $proto; 18 my $self = {}; 19 bless $self, $class; 20 21 return $self; 22 } 23 24 15 25 sub fetch { 16 26 my ($self, $input, %opts) = @_; 17 27 … … 62 72 if ( $content ) { 63 73 unless ( $encoding ) { 64 74 $encoding = $self->__try_content_encoding( substr($content, 0, 350) ); 65 if ( $encoding && $encoding ne 'utf-8' ) { 66 Encode::from_to($content, $encoding, 'utf-8'); 75 } 76 if ( $encoding && $encoding ne 'utf-8' ) { 77 warn "Encoding from $encoding\n..." if $DEBUG; 78 Encode::from_to($content, $encoding, 'utf-8'); 79 if ( exists $self->{headers} ) { 80 foreach my $header ( keys %{$self->{headers}} ) { 81 if ( ref $self->{headers}{$header} eq 'ARRAY' ) { 82 foreach my $val ( @{$self->{headers}{$header}} ) { 83 Encode::from_to($val, $encoding, 'utf-8'); 84 } 85 } else { 86 Encode::from_to($self->{headers}{$header}, $encoding, 'utf-8'); 87 } 88 } 67 89 } 68 90 } 69 91 $self->{encoding} = $encoding; … … 92 114 my ($self, $input)= @_; 93 115 if ( $input =~ /encoding[\ ]?=[\ ]?[\"\']?([a-z\-\d]+)/i ) { 94 116 return lc($1); 117 } elsif ( $input =~ /charset[\ ]?=[\ ]?[\"\']?([a-z\-\d]+)/i ) { 118 return lc($1); 95 119 } elsif ( $input =~ /(utf-8|windows-1251|koi8-r)/i ) { 96 120 return lc($1); 97 121 } else {