tmp nach /tmp gelegt
[kivitendo-erp.git] / 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