Skip to content

Commit e4f6068

Browse files
committed
Add test.lsp
1 parent b0e4290 commit e4f6068

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test.lsp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;; Returns CSV converted to list of lists
2+
;; (parse-csv "1,,'2,3',4.5,'6.7',hello,'\"world\"' \",; \t" "," "\"'" nil)
3+
(defun parse-csv (str delims quotes eols / len start end char fields records)
4+
(setq delims (if delims (vl-string->list delims))
5+
quotes (if quotes (vl-string->list quotes))
6+
eols (if eols (vl-string->list eols)))
7+
(setq len (strlen str)
8+
start 0
9+
end start)
10+
(while (< end len)
11+
(setq char (vl-string-elt str end))
12+
(cond ((member char quotes)
13+
(setq end (vl-string-position char str (1+ end))
14+
end (if end (1+ end) len)))
15+
((member char eols)
16+
(setq fields (cons (substr str (1+ start) (- end start)) fields)
17+
records (cons (reverse fields) records)
18+
fields nil
19+
start (1+ end)
20+
end start))
21+
((member char delims)
22+
(setq fields (cons (substr str (1+ start) (- end start)) fields)
23+
start (1+ end)
24+
end start))
25+
(t (setq end (1+ end)))))
26+
(setq fields (cons (substr str (1+ start) (- len start)) fields)
27+
records (cons (reverse fields) records))
28+
(reverse records))

0 commit comments

Comments
 (0)