SBCL using Unix line-ending conventions in Windows
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
This is SBCL 1.0.29 for Windows (XP). My first post was deleted. Please consider this report as important. Thanks
The below to read the test.csv file doesn't work well in sbcl
-------
test.csv:
one,two
three,four
five,six
-------
(defun get-token (delimiter string start)
(let ((pos (position delimiter string :start start)))
(cond ((null pos)
(cond ((= start (length string)) (values "" start))
(t (values (string-trim '(#\Space #\Tab #\Newline) (subseq string start)) (length string)))))
((= start pos) (values "" pos))
(t (values (string-trim '(#\Space #\Tab #\Newline) (subseq string start pos)) pos)))))
(defun read-csv-line (&optional input-stream eof-error-p eof-value recursive-p)
(let ((line (read-line input-stream eof-error-p eof-value recursive-p)))
(if (eq line eof-value) (return-from read-csv-line eof-value))
(loop with len = (length line) and pos = 0 and token
do (multiple-
(incf pos)
collect token
while (< pos len))))
(defun read-csv (input-stream &optional eof-error-p eof-value)
(when (not (eq eof-value (peek-char t input-stream eof-error-p eof-value)))
(loop for lst = (read-csv-line input-stream eof-error-p eof-value)
while (not (eq lst eof-value))
collect lst)))
(with-open-file (str "c:/test.csv" :direction :input)
;;In SBCL it doesn't work well!
*MYCSV*
") ("five" "six"))
However if one converts manually in msys $ tr -d '\r' <c:/test.csv> c:/unix.csv
and now it works:
(with-open-file (str "c:/test.csv" :direction :input)
*MYCSV2*
(("one" "two") ("three" "four") ("five" "six"))
Can we have this dos to unix conversion already set into sbcl so we don't have to convert manually every file before reading it in?