[NTG-context] Next problem with rfc4180splitter()

Jaroslav Hajtmar hajtmar at gyza.cz
Tue Sep 29 01:01:42 CEST 2015


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



More information about the ntg-context mailing list