On 2/26/2015 1:40 AM, Jaroslav Hajtmar wrote:
\starttext

\startluacode
local mycsvsplitter = utilities.parsers.rfc4180splitter{
     separator = ",",
     quote = '"',
}

local crap = io.loaddata("data.txt")

-- with header variant
local tablerows, columnname = mycsvsplitter(crap,true)
inspect(tablerows)
inspect(columnname)

-- without header variant
-- local tablerows = mycsvsplitter(crap)
-- inspect(tablerows)

for i=1,#tablerows do
     local l = tablerows[i]
      for j=1,#l do context(l[j]..", ")
     end
     context('\\crlf')
end

\stopluacode


\stoptext

line 527 in util-prs.lua:

local wholeblob = Ct((newline^(specification.strict and -1 or 1) * record)^0)

should do the trick

i'm not sure about the default as the standard might demand quit at empty line so that needs to be figured out (not by me therefore by you)

\starttext

\startluacode
local crap = [[
1,"2","3","4"
"a","b","c","d"
"foo","bar""baz","boogie","xyzzy"
"    ","    ","    ","     "
"And now","followed by","several","blank lines"


1,"2","3","4"
"a","b","c","d"
"foo","bar""baz","boogie","xyzzy"
"    ","    ","    ","     "
]]

local mycsvsplitter = {
    utilities.parsers.rfc4180splitter{
        separator = ",",
        quote = '"',
        strict = true,
    },
    utilities.parsers.rfc4180splitter{
        separator = ",",
        quote = '"',
    }
}

for i=1,#mycsvsplitter do
    local tablerows, columnname = mycsvsplitter[i](crap,true)
    context.formatted.title("Case %s",i)
    for i=1,#tablerows do
        local l = tablerows[i]
         for j=1,#l do context(l[j]..", ")
        end
        context('\\crlf')
    end
end
\stopluacode

\stoptext


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to