Refactor the charset guessing.
[pr0n] / perl / Sesse / pr0n / Common.pm
index 2ca54cfa7dedcc19a2b65b15baf37c9689599c57..bc598545a4b97e66da5a478710fbb6ff671ade62 100644 (file)
@@ -554,6 +554,20 @@ sub add_new_event {
        return ();
 }
 
+sub guess_charset {
+       my $text = shift;
+       my $decoded;
+
+       eval {
+               $decoded = Encode::decode("utf-8", $text, Encode::FB_CROAK);
+       };
+       if ($@) {
+               $decoded = Encode::decode("iso8859-1", $text);
+       }
+
+       return $decoded;
+}
+
 1;