Permalink
Browse files

simplify uri_escape

  • Loading branch information...
1 parent c4aa138 commit 926cdecd8bdff48c2e901f9e4a4eb61c92a37b40 @moritz moritz committed Aug 26, 2012
Showing with 6 additions and 12 deletions.
  1. +6 −12 lib/URI/Escape.pm
View
@@ -17,18 +17,12 @@ package URI::Escape {
sub uri_escape($s, Bool :$no_utf8 = False) is export {
return $s unless defined $s;
- $s.subst(:g, rx/<- [!*'()\-._~A..Za..z0..9]>+/,
- -> $escape {
- ($escape.Str.comb.map: {
- ( $no_utf8 || ! 0x80 +& ord($_) ) ?? %escapes{ $_ } !!
- do {
- my $buf = $_.encode;
- for (0 ..^ $buf.elems) {
- sprintf '%%%02X', $buf[ $_ ]
- }
- }
- }).join;
- });
+ $s.subst(:g, rx/<- [!*'()\-._~A..Za..z0..9]>/,
+ {
+ ( $no_utf8 || ! 0x80 +& ord(.Str) ) ?? %escapes{ .Str } !!
+ %escapes{.Str.encode.list>>.chr}.join;
+ }
+ );
}
# todo - automatic invalid UTF-8 detection

0 comments on commit 926cdec

Please sign in to comment.