Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use low level escapes lookup
  • Loading branch information
lizmat committed Jan 13, 2016
1 parent 1d413e4 commit 5410113
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/core/JSON/Pretty.pm
Expand Up @@ -37,16 +37,18 @@ my class JSONPrettyActions {

method str($/) { make ~$/ }

my %esc = '\\' => "\\",
'/' => "/",
'b' => "\b",
'n' => "\x0A",
't' => "\t",
'f' => "\f",
'r' => "\r",
'"' => "\"";
my $escapes := nqp::hash(
'\\' , "\\",
'/' , "/",
'b' , "\b",
'n' , "\x0A",
't' , "\t",
'f' , "\f",
'r' , "\r",
'"' , "\"",
);
method str_escape($/) {
make $<xdigit> ?? chr(:16($<xdigit>.join)) !! %esc.AT-KEY(~$/);
make $<xdigit> ?? chr(:16($<xdigit>.join)) !! nqp::atkey($escapes,~$/)
}
}

Expand Down

0 comments on commit 5410113

Please sign in to comment.