Correctly interpret CVS tables with quoted fields

The csv parser was very primitive, ignoring quoted fields.  This is
now fixed.
This commit is contained in:
Carsten Dominik 2009-10-26 12:31:16 +01:00
parent 1da2e348c4
commit 59c9c4cdd4
2 changed files with 24 additions and 9 deletions

View File

@ -1,5 +1,8 @@
2009-10-26 Carsten Dominik <carsten.dominik@gmail.com> 2009-10-26 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (org-table-convert-region): Correctly interpret
quoting in csv import.
* org.el (org-icompleting-read): Make iswitchb completion work * org.el (org-icompleting-read): Make iswitchb completion work
with lists and tables. with lists and tables.

View File

@ -424,17 +424,29 @@ nil When nil, the command tries to be smart and figure out the
((not (re-search-forward "^[^\n\t]+$" end t)) '(16)) ((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
((not (re-search-forward "^[^\n,]+$" end t)) '(4)) ((not (re-search-forward "^[^\n,]+$" end t)) '(4))
(t 1)))) (t 1))))
(setq re (cond
((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
((equal separator '(16)) "^\\|\t")
((integerp separator)
(format "^ *\\| *\t *\\| \\{%d,\\}" separator))
(t (error "This should not happen"))))
(goto-char beg) (goto-char beg)
(while (re-search-forward re end t) (if (equal separator '(4))
(replace-match "| " t t)) (while (<= (point) end)
;; parse the csv stuff
(cond
((looking-at "^") (insert "|"))
((looking-at "[ \t]*$") (replace-match "|") (beginning-of-line 2))
((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
(replace-match "\\1")
(if (looking-at "\"") (insert "\"")))
((looking-at "[^,\n]+") (goto-char (match-end 0)))
((looking-at "[ \t]*,") (replace-match " | "))
(t (beginning-of-line 2)
(if (< (point) end) (insert "|")))))
(setq re (cond
((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
((equal separator '(16)) "^\\|\t")
((integerp separator)
(format "^ *\\| *\t *\\| \\{%d,\\}" separator))
(t (error "This should not happen"))))
(while (re-search-forward re end t)
(replace-match "| " t t)))
(goto-char beg) (goto-char beg)
(insert " ")
(org-table-align))) (org-table-align)))
(defun org-table-import (file arg) (defun org-table-import (file arg)