json.writer: make sure we make hex values two digits zero padded.

db4
John Benediktsson 2015-01-04 09:37:03 -08:00
parent 1ec43d7913
commit 2453a785f7
2 changed files with 6 additions and 4 deletions

View File

@ -71,3 +71,7 @@ TUPLE: person first-name age ;
{ "\"\\ud834\\udd1e\"" }
[ t json-escape-unicode? [ "𝄞" >json ] with-variable ] unit-test
{ "\"\\ud800\\udc01\"" }
[ t json-escape-unicode? [ "𐀁" >json ] with-variable ] unit-test

View File

@ -44,12 +44,10 @@ M: json-null stream-json-print
: json-print-generic-escape-surrogate-pair ( stream char -- stream )
0x10000 - [ encode-first ] [ encode-second ] bi
"\\u%x%x\\u%x%x" sprintf over stream-write ;
"\\u%02x%02x\\u%02x%02x" sprintf over stream-write ;
: json-print-generic-escape-bmp ( stream char -- stream )
"\\u" pick stream-write
>hex 4 CHAR: 0 pad-head
over stream-write ;
"\\u%04x" sprintf over stream-write ;
: json-print-generic-escape ( stream char -- stream )
dup 0xffff > [