--- reg +++ reg @@ -108,0 +109,3 @@ + (?{ + $MATCH = token_string( @{ $MATCH{char} } ); + }) @@ -111 +114,4 @@ - | (?: \x22 | \x5C | \x2F | \x62 | \x66 | \x6E | \x72 | \x74 | (?: \x75 (?: ){4} ) ) + | (?: <.escape> ) + + + \x22 | \x5C | \x2F | \x62 | \x66 | \x6E | \x72 | \x74 | \x75[1-9A-F]{4} @@ -129 +135 @@ -for my $str( q{[ "\\" quote \\t tab" ]} , ){ +for my $str( q{[ "\\" quote \\t tab \\uD83D\\uDC2A U+1F42A DROMEDARY CAMEL" ]}, ){ @@ -140,0 +147,23 @@ +BEGIN { + my %rep = ( + "\"" => '"', + "/" => '/', + "\\" => '\\', + b => "\b", + f => "\f", + n => "\n", + r => "\r", + t => "\t" + ); + sub token_string { + return join '', + map { + my $ret = $_; + if( ref $_ ){ + $ret = $rep{ $_->{escaped} }; + $ret ||= pack('U', hex substr $_->{escaped}, 1, 4 ); + } + $ret; + } @_; + } +}