From 77f1de6e3613b47722e73dfa2254c5dd87a23c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Tue, 4 Jul 2023 22:44:43 +0200 Subject: [PATCH] Use duck for util-csv exclusively. --- doc/d-utils.md | 12 ++++++++++++ doc/utils.md | 23 ----------------------- src/util-csv.scm | 13 ++++++++----- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/doc/d-utils.md b/doc/d-utils.md index 8f7c09c..b149324 100644 --- a/doc/d-utils.md +++ b/doc/d-utils.md @@ -51,3 +51,15 @@ Curried version of fast CSV line parser with given separator and string delimite * ```separator``` - separator character * ```string-delimiger``` - string quotation character * ```line``` - line to parse + +### csv-parse-lines [procedure] + + (csv-parse-lines lines separator: (separator ;) string-delimiter: (string-delimiter ")) + +Parses given lines and returns list of lists of strings. + +### csv-parse [procedure] + + (csv-parse fn . args) + +Uses ```csv-parse-lines``` on lines read from given file ```fn```. diff --git a/doc/utils.md b/doc/utils.md index 328015c..2d82f07 100644 --- a/doc/utils.md +++ b/doc/utils.md @@ -8,29 +8,6 @@ well. The modules are listed in alphabetical order. -### CSV - - (import util-csv) - -This module provides a very simple, incomplete and incorrect but fast -CSV loader. - - (csv-parse filename - [#:separator #\;] - [#:string-delimiter #\"]) - -* ```separator``` - cell separator in CSV file -* ```string-delimiter``` - for introducing strings possibly with separators - -Parses given CSV file and returns list of lists of strings -representing its contents. - - (csv-split-header csv) - -* ```csv``` - list of lists of strings - -Splits given loaded CSV into two tables at the first empty row. - ### Dictionary (import util-dict-list) diff --git a/src/util-csv.scm b/src/util-csv.scm index 67dc84f..2a2e089 100644 --- a/src/util-csv.scm +++ b/src/util-csv.scm @@ -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)