Created
July 12, 2009 14:15
-
-
Save masak/145647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Performs URI escaping so that you can construct proper | |
# query strings faster. | |
sub escape($s) is export { | |
# RAKUDO: Need 'H2' in Rakudo's unpack before this works | |
# RAKUDO: Also need to turn the string into bytes before letting | |
# the substitution loose on it. | |
return (~$s).subst(/<-[ a..zA..Z0..9_.\-]>+/, | |
{ '%' ~ unpack(~$/, "H2" x $/.chars).join('%').uc }, | |
:global).trans(' ' => '+'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment