Use duck for util-csv exclusively.

This commit is contained in:
Dominik Pantůček 2023-07-04 22:44:43 +02:00
parent 2fb41c172e
commit 77f1de6e36
3 changed files with 20 additions and 28 deletions

View file

@ -96,9 +96,10 @@ CSV loader.")
(cons (cons token (car res)) (cdr res))
2)))))))) ; Continue inside quoted data
;; Parses given CSV lines list
(define* (csv-parse-lines lines
#:separator (separator #\;)
#:string-delimiter (string-delimiter #\"))
(define*/doc (csv-parse-lines lines
#:separator (separator #\;)
#:string-delimiter (string-delimiter #\"))
("Parses given lines and returns list of lists of strings.")
(let* ((csv-parse-line (make-csv-line-parser separator string-delimiter))
(total (max (sub1 (length lines)) 1)))
(let loop ((lines lines)
@ -114,7 +115,8 @@ CSV loader.")
res)))))))
;; Loads given CSV file and parses its lines into lists
(define (csv-parse fn . args)
(define/doc (csv-parse fn . args)
("Uses ```csv-parse-lines``` on lines read from given file ```fn```.")
(call/cc
(lambda (ret)
(with-exception-handler
@ -125,7 +127,8 @@ CSV loader.")
(apply csv-parse-lines lines args)))))))
;; Splits CSV into header and body based on the first empty row.
(define (csv-split-header csv)
(define/doc (csv-split-header csv)
("Splits given loaded CSV into two tables at the first empty row.")
(let loop ((body csv)
(rhead '()))
(if (null? body)