Simplify decoding code into one `cond'.
(It's likely to get written in some better way, for example, avoid the
extra work for simple strings.)
(cherry picked from commit 210c71d91c
)
This commit is contained in:
parent
eb9b3e109a
commit
cc655dc13b
|
@ -172,16 +172,16 @@ See more in PR8831.
|
||||||
(if (null? l) '()
|
(if (null? l) '()
|
||||||
(let* ([c (car l)] [l (cdr l)]
|
(let* ([c (car l)] [l (cdr l)]
|
||||||
[hex (and (equal? #\% c) (pair? l) (pair? (cdr l))
|
[hex (and (equal? #\% c) (pair? l) (pair? (cdr l))
|
||||||
(string->number (string (car l) (cadr l)) 16))])
|
(string->number (string (car l) (cadr l)) 16))]
|
||||||
(if hex
|
[rest (internal-decode (if hex (cddr l) l))])
|
||||||
(cons hex (internal-decode (cddr l)))
|
(cond [hex (cons hex rest)]
|
||||||
(append (if (char<? c max-ascii)
|
[(char<? c max-ascii) (cons (vector-ref table (char->integer c))
|
||||||
(list (vector-ref table (char->integer c)))
|
rest)]
|
||||||
;; This should probably error, but strings to be decoded
|
;; This should probably error, but strings to be decoded
|
||||||
;; might come from misbehaving sources; maybe it's better
|
;; might come from misbehaving sources; maybe it's
|
||||||
;; to add some parameter for a permissive mode
|
;; better to add some parameter for a permissive mode
|
||||||
(bytes->list (string->bytes/utf-8 (string c))))
|
[else (append (bytes->list (string->bytes/utf-8 (string c)))
|
||||||
(internal-decode l))))))
|
(internal-decode l))]))))
|
||||||
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))
|
(bytes->string/utf-8 (apply bytes (internal-decode (string->list str)))))
|
||||||
|
|
||||||
;; Utility for defining codecs
|
;; Utility for defining codecs
|
||||||
|
|
Loading…
Reference in New Issue
Block a user