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:
parent
1da2e348c4
commit
59c9c4cdd4
|
@ -1,5 +1,8 @@
|
|||
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
|
||||
with lists and tables.
|
||||
|
||||
|
|
|
@ -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,]+$" end t)) '(4))
|
||||
(t 1))))
|
||||
(goto-char beg)
|
||||
(if (equal separator '(4))
|
||||
(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"))))
|
||||
(goto-char beg)
|
||||
(while (re-search-forward re end t)
|
||||
(replace-match "| " t t))
|
||||
(replace-match "| " t t)))
|
||||
(goto-char beg)
|
||||
(insert " ")
|
||||
(org-table-align)))
|
||||
|
||||
(defun org-table-import (file arg)
|
||||
|
|
Loading…
Reference in New Issue