X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/8456963f5d7c483cd9f330095be03e457033b472..a200453a04fc89fdf02dbe39e1d951cb1b55191c:/SL/Iconv.pm diff --git a/SL/Iconv.pm b/SL/Iconv.pm new file mode 100644 index 000000000..29bf99df4 --- /dev/null +++ b/SL/Iconv.pm @@ -0,0 +1,31 @@ +package SL::Iconv; + +use Text::Iconv; + +use SL::Common; + +use vars qw(%converters); + +sub get_converter { + my ($from_charset, $to_charset) = @_; + + my $index = "${from_charset}::${to_charset}"; + if (!$converters{$index}) { + $converters{$index} = Text::Iconv->new($from_charset, $to_charset) || die; + } + + return $converters{$index}; +} + +sub convert { + my ($from_charset, $to_charset, $text) = @_; + + $from_charset ||= Common::DEFAULT_CHARSET; + $to_charset ||= Common::DEFAULT_CHARSET; + + my $converter = get_converter($from_charset, $to_charset); + return $converter->convert($text); +} + +1; +