Skip to content

Instantly share code, notes, and snippets.

@masak
Created July 12, 2009 14:15
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 masak/145647 to your computer and use it in GitHub Desktop.
Save masak/145647 to your computer and use it in GitHub Desktop.
# 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