Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1465be33

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

CSV-Export mit UTF-8 als Encoding gefixt

Dabei die Abhängigkeit vom Modul IO::Wrap beseitigt.

Unterschiede anzeigen:

SL/ReportGenerator.pm
1 1
package SL::ReportGenerator;
2 2

  
3 3
use Data::Dumper;
4
use IO::Wrap;
5 4
use List::Util qw(max);
6 5
use Text::CSV_XS;
7 6
#use PDF::API2;    # these two eat up to .75s on startup. only load them if we actually need them
......
688 687
}
689 688

  
690 689
sub unescape_string {
691
  my $self  = shift;
692
  my $text  = shift;
690
  my ($self, $text, $do_iconv) = @_;
693 691

  
694
  $text     = $main::locale->unquote_special_chars('HTML', $text);
695
  $text     = $::locale->{iconv}->convert($text);
692
  $text = $main::locale->unquote_special_chars('HTML', $text);
693
  $text = $::locale->{iconv}->convert($text) if $do_iconv;
696 694

  
697 695
  return $text;
698 696
}
......
718 716
                                'quote_char'  => $quote_char,
719 717
                                'eol'         => $eol, });
720 718

  
721
  my $stdout          = wraphandle(\*STDOUT);
722 719
  my @visible_columns = $self->get_visible_columns('CSV');
723 720

  
721
  my $stdout;
722
  open $stdout, '>-';
723
  binmode $stdout, ':encoding(utf8)' if $::locale->is_utf8;
724

  
724 725
  if ($opts->{headers}) {
725 726
    if (!$self->{custom_headers}) {
726
      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}) } @visible_columns ]);
727
      $csv->print($stdout, [ map { $self->unescape_string($self->{columns}->{$_}->{text}, 1) } @visible_columns ]);
727 728

  
728 729
    } else {
729 730
      foreach my $row (@{ $self->{custom_headers} }) {

Auch abrufbar als: Unified diff