Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rakudo finally does both Str.trans and backslash escapes in char classes

  • Loading branch information...
commit 4e7ec0c7f841db27855addc12fd9bc470b2411d6 1 parent 87dbbaa
@moritz authored
Showing with 3 additions and 20 deletions.
  1. +3 −20 lib/JSON/Tiny.pm
View
23 lib/JSON/Tiny.pm
@@ -23,27 +23,10 @@ proto to-json($) is export {*}
multi to-json(Real:D $d) { ~$d }
multi to-json(Bool:D $d) { $d ?? 'true' !! 'false'; }
multi to-json(Str:D $d) {
-# RAKUDO/nom doesn't do .trans yet
-# '"'
-# ~ (~$d).trans(['"', '\\', "\b", "\f", "\n", "\r", "\t"]
-# => ['\"', '\\\\', '\b', '\f', '\n', '\r', '\t'])\
-# # RAKUDO: This would be nicer to write as <-[\c32..\c126]>,
-# # but Rakudo doesn't do \c yet. [perl #73698]
-# .subst(/<-[\ ..~]>/, { ord(~$_).fmt('\u%04x') }, :g)
-# ~ '"'
- state %esc =
- '"' => '\"',
- '\\' => '\\\\',
- "\b" => '\b',
- "\f" => '\f',
- "\n" => '\n',
- "\r" => '\r',
- "\t" => '\t',
- ;
-
'"'
- ~ $d.subst(/<["\\\b\f\n\r\t]>/, -> $/ { %esc{$/} }, :g)\
- .subst(/<-[\ ..~]>/, { ord(~$_).fmt('\u%04x') }, :g)
+ ~ (~$d).trans(['"', '\\', "\b", "\f", "\n", "\r", "\t"]
+ => ['\"', '\\\\', '\b', '\f', '\n', '\r', '\t'])\
+ .subst(/<-[\c32..\c126]>/, { ord(~$_).fmt('\u%04x') }, :g)
~ '"'
}
multi to-json(Array:D $d) {
Please sign in to comment.
Something went wrong with that request. Please try again.