История изменений
Исправление ados, (текущая версия) :
Как-то так похоже:
(module-define!
(resolve-module '(web http))
'parse-key-value-list
(lambda* (parse-key-value-list str #:optional
(val-parser default-val-parser)
(start 0) (end (string-length str)))
(let lp ((i start))
(if (not (< i end))
'()
(let* ((i (skip-whitespace str i end))
(eq (string-index str #\= i end))
(comma (min (string-index str #\, i end) (string-index str #\; i end)))
(delim (min (or eq end) (or comma end)))
(k (string->symbol
(substring str i (trim-whitespace str i delim)))))
(call-with-values
(lambda ()
(if (and eq (or (not comma) (< eq comma)))
(let ((i (skip-whitespace str (1+ eq) end)))
(if (and (< i end) (eqv? (string-ref str i) #\"))
(parse-qstring str i end #:incremental? #t)
(values (substring str i
(trim-whitespace str i
(or comma end)))
(or comma end))))
(values #f delim)))
(lambda (v-str next-i)
(let ((v (val-parser k v-str))
(i (skip-whitespace str next-i end)))
(unless (or (= i end) (eqv? (string-ref str i) #\,) (eqv? (string-ref str i) #\;))
(bad-header-component 'key-value-list
(substring str start end)))
(cons (if v (cons k v) k)
(lp (1+ i)))))))))))
Исходная версия ados, :
Как-то так похоже:
(module-define!
(resolve-module '(web client))
'parse-key-value-list
(lambda* (parse-key-value-list str #:optional
(val-parser default-val-parser)
(start 0) (end (string-length str)))
(let lp ((i start))
(if (not (< i end))
'()
(let* ((i (skip-whitespace str i end))
(eq (string-index str #\= i end))
(comma (min (string-index str #\, i end) (string-index str #\; i end)))
(delim (min (or eq end) (or comma end)))
(k (string->symbol
(substring str i (trim-whitespace str i delim)))))
(call-with-values
(lambda ()
(if (and eq (or (not comma) (< eq comma)))
(let ((i (skip-whitespace str (1+ eq) end)))
(if (and (< i end) (eqv? (string-ref str i) #\"))
(parse-qstring str i end #:incremental? #t)
(values (substring str i
(trim-whitespace str i
(or comma end)))
(or comma end))))
(values #f delim)))
(lambda (v-str next-i)
(let ((v (val-parser k v-str))
(i (skip-whitespace str next-i end)))
(unless (or (= i end) (eqv? (string-ref str i) #\,) (eqv? (string-ref str i) #\;))
(bad-header-component 'key-value-list
(substring str start end)))
(cons (if v (cons k v) k)
(lp (1+ i)))))))))))