Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazeburo/8969798 to your computer and use it in GitHub Desktop.
Save kazeburo/8969798 to your computer and use it in GitHub Desktop.
our %EncodeMap;
for my $num ( 0 .. 255 ) {
my $chr = chr $num;
my $h = sprintf "%02X", $num;
$EncodeMap{$chr} = '%'. uc $h;
}
$EncodeMap{" "} = '+';
sub url_escape {
return '' unless defined $_[0];
my $t = shift;
$t =~ s!([^A-Za-z0-9\-\._~]+)!
join '', @EncodeMap{exists $EncodeMap{$1} ? ($1) : ($1 =~ /(\C)/gs)}
!gsxe;
return $t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment