ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jaroslav Hajtmar <hajtmar@gyza.cz>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: CSV scanners built in ConTeXt - feature or bug?
Date: Thu, 26 Feb 2015 01:40:41 +0100	[thread overview]
Message-ID: <54EE6B89.4090504@gyza.cz> (raw)

Hi ConTeXist
A few days ago Hans pointed me builtin CSV splitter. I tried to test it 
sure will come in handy for my needs. I found that if the CSV file 
contain a blank line, then it stops processing the file (see my minimal 
example). It is clear to me that the incorrectness of file format (eg. 
different number of columns in rows etc.) may cause interruption of 
processing, however, I want to ask whether there is an opportunity to 
process the CSV file with blank lines until the end of CSV file. I 
noticed that when I exporting data from Excel sometimes happens that in 
the export file will appear blank line. Is it interrupt processing a 
feature of a buildin splitter or is it a bug? Can it possibly somehow 
fix or add new functionality?

Thanx
Jaroslav Hajtmar



Here is minimal example:

\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




% <-------------- here start data.txt file ---------------------->
first,second,third,fourth
1,"2","3","4"
"a","b","c","d"
"foo","bar""baz","boogie","xyzzy"
"    ","    ","    ","     "
"And now","followed by","several","blank lines"




"After several","empty rows","data continues","here"
11,"22","33","44"
"aa","bb","cc","dd"
% <-------------- and here stop data.txt file ---------------------->





___________________________________________________________________________________
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	other threads:[~2015-02-26  0:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26  0:40 Jaroslav Hajtmar [this message]
2015-02-26  9:47 ` Hans Hagen
2015-02-26 11:20   ` Alan BRASLAU
2015-02-26 13:26     ` Jaroslav Hajtmar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54EE6B89.4090504@gyza.cz \
    --to=hajtmar@gyza.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).