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-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
|
||||
[#\\ (! "\\\\")]
|
||||
[#\u08 (! "\\b")]
|
||||
|
@ -579,7 +579,7 @@
|
|||
[#\u0A (! "\\n")]
|
||||
[#\u0D (! "\\r")]
|
||||
[#\u09 (! "\\t")]
|
||||
[_ (! "~a" c)]))
|
||||
[_ (default c)]))
|
||||
|
||||
(define (write-sequence opener comma closer item-writer vs)
|
||||
(! "~a" opener)
|
||||
|
@ -627,12 +627,15 @@
|
|||
(! "\"")]
|
||||
[(? bytes?)
|
||||
(! "#\"")
|
||||
(for [(c (in-bytes v))]
|
||||
(match c
|
||||
(for [(b (in-bytes v))]
|
||||
(match b
|
||||
[#x22 (! "\\\"")]
|
||||
[#x5C (! "\\\\")]
|
||||
[(? binunescaped?) (! "~a" (integer->char c))]
|
||||
[_ (! "\\x~a" (~a #:min-width 2 #:align 'right #:left-pad-string "0" (number->string c 16)))]))
|
||||
[(? binunescaped?) (write-stringlike-char (integer->char b))]
|
||||
[_ (write-stringlike-char (integer->char b)
|
||||
(lambda (c) (! "\\x~a" (~a #:min-width 2
|
||||
#:align 'right
|
||||
#:left-pad-string "0"
|
||||
(number->string b 16)))))]))
|
||||
(! "\"")]
|
||||
[(? symbol?)
|
||||
(define s (symbol->string v))
|
||||
|
|
Loading…
Reference in New Issue