mirror of
https://github.com/kanaka/mal.git
synced 2024-11-11 00:52:44 +03:00
Fix unescaping in go, perl
This commit is contained in:
parent
e73fcefe8f
commit
0794206dc5
@ -69,9 +69,11 @@ func read_atom(rdr Reader) (MalType, error) {
|
||||
str := (*token)[1 : len(*token)-1]
|
||||
return strings.Replace(
|
||||
strings.Replace(
|
||||
strings.Replace(str, `\"`, `"`, -1),
|
||||
strings.Replace(
|
||||
strings.Replace(str, `\\`, "\u029e", -1),
|
||||
`\"`, `"`, -1),
|
||||
`\n`, "\n", -1),
|
||||
`\\`, "\\", -1), nil
|
||||
"\u029e", "\\", -1), nil
|
||||
} else if (*token)[0] == ':' {
|
||||
return NewKeyword((*token)[1:len(*token)])
|
||||
} else if *token == "nil" {
|
||||
|
@ -32,10 +32,9 @@ sub read_atom {
|
||||
given ($token) {
|
||||
when(/^-?[0-9]+$/) { return Integer->new($token) }
|
||||
when(/^"/) {
|
||||
my %escaped_chars = ( "\\\\" => "\\", "\\\"" => "\"", "\\n" => "\n" );
|
||||
my $str = substr $token, 1, -1;
|
||||
$str =~ s/\\"/"/g;
|
||||
$str =~ s/\\n/\n/g;
|
||||
$str =~ s/\\\\/\\/g;
|
||||
$str =~ s/\\./$escaped_chars{$&}/ge;
|
||||
return String->new($str)
|
||||
}
|
||||
when(/^:/) { return _keyword(substr($token,1)) }
|
||||
|
Loading…
Reference in New Issue
Block a user