]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Iconv.pm
Kleines Hilfsmodul für Zeichensatzkonvertierung hinzugefügt. In am.pl und rp.pl werde...
[mfinanz.git] / SL / Iconv.pm
diff --git a/SL/Iconv.pm b/SL/Iconv.pm
new file mode 100644 (file)
index 0000000..29bf99d
--- /dev/null
@@ -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;
+