Patch for CSV library
Joseph Donaldson <[email protected]>
| Newsgroups | gmane.lisp.scheme.bigloo |
|---|---|
| Message-ID | <[email protected]> |
Hello, Recently, when attempting to parse a tab-delimited file with the CSV library, I realized that I had introduced a bug when I modified the parser to accept comma-separated value files with records like the following: "dog" , "cat" , "pig" The change allowed space characters (tab and space) to be between the quoted data and the separator character. Unfortunately, this broke the proper handling of files that used space or tab as a delimiters. The patch attached corrects this but keeps the original behavior if the delimiter and quote characters are not space or tab. The patch is against bigloo4.1a-beta31Jan14. Best Regards, Joseph Donaldson
csv.patch
(text/x-patch, 1.1 KB)
--- bigloo4.1a/api/csv/src/Llib/csv.sch 2014-01-30 14:31:23.000000000 -0500 +++ bigloo4.1amod/api/csv/src/Llib/csv.sch 2014-02-02 18:47:13.993593822 -0500 @@ -20,13 +20,26 @@ ((when in-quote? (: quote quote)) (cons '2quote (string ,quot))) - (quote + (quote (begin (set! in-quote? (not in-quote?)) (cons 'kwote (the-string)))) - ((when (not in-quote?) - (+ (or #\space #\tab))) - (cons 'space (the-string))) + ,(cond ((and (or (char=? sep #\space) + (char=? quot #\space)) + (or (char=? sep #\tab) + (char=? quot #\tab))) + `(define ,(gensym 'dummy) #unspecified)) + ((or (char=? sep #\space) + (char=? quot #\space)) + '((when (not in-quote?) (+ #\tab)) + (cons 'space (the-string)))) + ((or (char=? sep #\tab) + (char=? quot #\tab)) + '((when (not in-quote?) (+ #\space)) + (cons 'space (the-string)))) + (else + '((when (not in-quote?) (+ (or #\space #\tab))) + (cons 'space (the-string))))) (separator 'separator) ((or (: #\return #\newline)