SVN: toys/rsget.pl/RSGet/Curl.pm

sparky sparky at pld-linux.org
Thu Jun 17 03:18:55 CEST 2010


Author: sparky
Date: Thu Jun 17 03:18:55 2010
New Revision: 11564

Modified:
   toys/rsget.pl/RSGet/Curl.pm
Log:
- use perl's builtin utf8 encoder/decoder; fallback to vim-like byte encoding
  (<8f>) if that fails -- done to avoid Encode.pm requirement (almost 2 megs
  of useless char tables)


Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm	(original)
+++ toys/rsget.pl/RSGet/Curl.pm	Thu Jun 17 03:18:55 2010
@@ -16,7 +16,6 @@
 use File::Copy ();
 use File::Path;
 use Fcntl qw(SEEK_SET);
-use Encode;
 set_rev qq$Id$;
 
 def_settings(
@@ -299,7 +298,18 @@
 		$eurl =~ s/\?.*$//;
 		$fname = de_ml( uri_unescape( $eurl ) );
 	}
-	$fname = encode_utf8( decode_utf8( $fname ) );
+
+	{
+		local $SIG{__DIE__} = 'DEFAULT';
+		eval {
+			utf8::decode( $fname );
+			utf8::encode( $fname );
+		};
+		if ( $@ ) {
+			# as a fallback kill all non-ascii chars
+			$fname =~ s/([^[:ascii:]])/sprintf "<%.2x>", ord($1)/eg;
+		}
+	}
 
 	if ( my $fn = $supercurl->{fname} ) {
 		if ( $fname ne $fn ) {


More information about the pld-cvs-commit mailing list