Hello ConTeXist,
Some time ago, Hans solved my problem with the splitter. Now I solve
correction an error in my module, which to me signaled Pablo Rodriguez.
The problem is with jednosloupcovými CSV files, which thus do not
contain separators row fields. Pablo say, that CSV files without colon
contains separators, because line breaks are separators. Commas—or
semicolons—are required when having more than a cell in the same line.
For example LibreOffice Calc spares the final semicolon when only the
file only contains one column and this behavior seems to be right,
according to the RFC4180: Common Format and MIME Type for
Comma-Separated Values (CSV) Files. We think that the final comma
separator should optional, not mandatory.
The following example shows, however, that rfc4180splitter () in
onecolumn CSV file fails and falls with an error. Making I'm a mistake
somewhere, or is something else wrong with the splitter?
Thanx Jaroslav Hajtmar
Here is minimal example:
\starttext
% mycsvfile.txt content one column data without separator:
% a
% b
% c
% d
% e
% f
% myothercsvfile.txt content two columns data:
% a,1
% b,2
% c,3
% d,4
% e,5
% f,6
\startluacode
local mycsvsplitter = utilities.parsers.rfc4180splitter()
-- local crap = io.loaddata("mycsvfile.txt") -- crashed (error code
attempt to index field - a nil value)
local crap = io.loaddata("myothercsvfile.txt") -- work fine
local list, names = mycsvsplitter(crap) inspect(list) inspect(names)
l = list
for i = 1, 6 do
context(l[i][1]..', ')
end
\stopluacode
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________