Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a200453a

Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt

  • ID a200453a04fc89fdf02dbe39e1d951cb1b55191c
  • Vorgänger 8456963f
  • Nachfolger d52e2ffc

Kleines Hilfsmodul für Zeichensatzkonvertierung hinzugefügt. In am.pl und rp.pl werden die hardcodierten Umlaute auch in den Ausgabezeichensatz konvertiert.

Unterschiede anzeigen:

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

  
3
use Text::Iconv;
4

  
5
use SL::Common;
6

  
7
use vars qw(%converters);
8

  
9
sub get_converter {
10
  my ($from_charset, $to_charset) = @_;
11

  
12
  my $index = "${from_charset}::${to_charset}";
13
  if (!$converters{$index}) {
14
    $converters{$index} = Text::Iconv->new($from_charset, $to_charset) || die;
15
  }
16

  
17
  return $converters{$index};
18
}
19

  
20
sub convert {
21
  my ($from_charset, $to_charset, $text) = @_;
22

  
23
  $from_charset ||= Common::DEFAULT_CHARSET;
24
  $to_charset   ||= Common::DEFAULT_CHARSET;
25

  
26
  my $converter = get_converter($from_charset, $to_charset);
27
  return $converter->convert($text);
28
}
29

  
30
1;
31

  
SL/User.pm
36 36

  
37 37
use IO::File;
38 38
use Fcntl qw(:seek);
39
use Text::Iconv;
40 39

  
41 40
use SL::DBUpgrade2;
42 41
use SL::DBUtils;
42
use SL::Iconv;
43 43

  
44 44
sub new {
45 45
  $main::lxdebug->enter_sub();
......
460 460

  
461 461
  $db_charset ||= Common::DEFAULT_CHARSET;
462 462

  
463
  my $iconv = Text::Iconv->new($file_charset, $db_charset);
463
  my $iconv = SL::Iconv::get_converter($file_charset, $db_charset);
464 464

  
465 465
  $dbh->begin_work();
466 466

  
......
524 524

  
525 525
  $db_charset ||= Common::DEFAULT_CHARSET;
526 526

  
527
  my $iconv = Text::Iconv->new($file_charset, $db_charset);
528

  
529 527
  $dbh->begin_work();
530 528

  
531 529
  while (<$fh>) {
532
    $_ = $iconv->convert($_);
530
    $_ = SL::Iconv::convert($file_charset, $db_charset, $_);
533 531

  
534 532
    # Remove DOS and Unix style line endings.
535 533
    chomp;
......
912 910
  my $db_charset = $main::dbcharset;
913 911
  $db_charset ||= Common::DEFAULT_CHARSET;
914 912

  
915
  my %converters;
916

  
917 913
  foreach my $db (split / /, $form->{dbupdate}) {
918 914

  
919 915
    next unless $form->{$db};
......
949 945
    foreach my $control (@upgradescripts) {
950 946
      next if ($control->{"applied"});
951 947

  
952
      if (!$converters{$control->{charset}}) {
953
        $converters{$control->{charset}} = Text::Iconv->new($control->{charset}, $db_charset);
954
      }
955
      $control->{description} = $converters{$control->{charset}}->convert($control->{description});
948
      $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description});
956 949

  
957 950
      $control->{"file"} =~ /\.(sql|pl)$/;
958 951
      my $file_type = $1;
bin/mozilla/am.pl
36 36
use SL::Form;
37 37
use SL::User;
38 38
use SL::USTVA;
39
use SL::Iconv;
39 40
use CGI::Ajax;
40 41
use CGI;
41 42

  
......
223 224
          30 => "Ausserordentlicher Aufwand",
224 225
          31 => "Betriebliche Steuern");
225 226
  foreach $item (sort({ $a <=> $b } keys(%eur))) {
227
    my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item}));
226 228
    if ($item == $form->{pos_eur}) {
227
      $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $eur{$item}</option>\n|;
229
      $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
228 230
    } else {
229
      $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $eur{$item}</option>\n|;
231
      $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
230 232
    }
231 233

  
232 234
  }
......
256 258
             34 => 'Verr.kalk.Kosten',
257 259
             35 => 'Steuern Eink.u.Ertr.');
258 260
  foreach $item (sort({ $a <=> $b } keys %bwapos)) {
261
    my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item}));
259 262
    if ($item == $form->{pos_bwa}) {
260
      $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $bwapos{$item}\n|;
263
      $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
261 264
    } else {
262
      $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $bwapos{$item}\n|;
265
      $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
263 266
    }
264 267

  
265 268
  }
bin/mozilla/rp.pl
41 41
use SL::PE;
42 42
use SL::RP;
43 43
use SL::USTVA;
44
use SL::Iconv;
44 45

  
45 46
1;
46 47

  
......
2009 2010
     " " => "_"
2010 2011
    );
2011 2012

  
2013
  foreach my $key (keys %replacements) {
2014
    my $new_key = SL::Iconv::convert("ISO-8859-15", $dbcharset, $key);
2015
    $replacements{$new_key} = $replacements{$key} if $new_key ne $key;
2016
  }
2017

  
2012 2018
  $form->{statementdate} = $locale->date(\%myconfig, $form->{todate}, 1);
2013 2019

  
2014 2020
  $form->{templates} = "$myconfig{templates}";

Auch abrufbar als: Unified diff