Fix byte string output for control characters
This commit is contained in:
parent
467da29c56
commit
1bb7e1862e
|
@ -571,7 +571,7 @@
|
||||||
(define (write-preserve v0 [o (current-output-port)])
|
(define (write-preserve v0 [o (current-output-port)])
|
||||||
(define-syntax-rule (! fmt arg ...) (fprintf o fmt arg ...))
|
(define-syntax-rule (! fmt arg ...) (fprintf o fmt arg ...))
|
||||||
|
|
||||||
(define (write-stringlike-char c)
|
(define (write-stringlike-char c [default (lambda (c) (! "~a" c))])
|
||||||
(match c
|
(match c
|
||||||
[#\\ (! "\\\\")]
|
[#\\ (! "\\\\")]
|
||||||
[#\u08 (! "\\b")]
|
[#\u08 (! "\\b")]
|
||||||
|
@ -579,7 +579,7 @@
|
||||||
[#\u0A (! "\\n")]
|
[#\u0A (! "\\n")]
|
||||||
[#\u0D (! "\\r")]
|
[#\u0D (! "\\r")]
|
||||||
[#\u09 (! "\\t")]
|
[#\u09 (! "\\t")]
|
||||||
[_ (! "~a" c)]))
|
[_ (default c)]))
|
||||||
|
|
||||||
(define (write-sequence opener comma closer item-writer vs)
|
(define (write-sequence opener comma closer item-writer vs)
|
||||||
(! "~a" opener)
|
(! "~a" opener)
|
||||||
|
@ -627,12 +627,15 @@
|
||||||
(! "\"")]
|
(! "\"")]
|
||||||
[(? bytes?)
|
[(? bytes?)
|
||||||
(! "#\"")
|
(! "#\"")
|
||||||
(for [(c (in-bytes v))]
|
(for [(b (in-bytes v))]
|
||||||
(match c
|
(match b
|
||||||
[#x22 (! "\\\"")]
|
[#x22 (! "\\\"")]
|
||||||
[#x5C (! "\\\\")]
|
[(? binunescaped?) (write-stringlike-char (integer->char b))]
|
||||||
[(? binunescaped?) (! "~a" (integer->char c))]
|
[_ (write-stringlike-char (integer->char b)
|
||||||
[_ (! "\\x~a" (~a #:min-width 2 #:align 'right #:left-pad-string "0" (number->string c 16)))]))
|
(lambda (c) (! "\\x~a" (~a #:min-width 2
|
||||||
|
#:align 'right
|
||||||
|
#:left-pad-string "0"
|
||||||
|
(number->string b 16)))))]))
|
||||||
(! "\"")]
|
(! "\"")]
|
||||||
[(? symbol?)
|
[(? symbol?)
|
||||||
(define s (symbol->string v))
|
(define s (symbol->string v))
|
||||||
|
|
Loading…
Reference in New Issue