lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> I have a question about csv parser.
> For most of the codes I can search(including lpeg and
> even python's module), they show how to break a
> "record" or csv line into fields.
> Now if I have a file like the following :
> "this is a field with \r\n", 2, 3 \r\n
> normal, 2, 3 \r\n
> how do I read the correct line as the quoted \r\n
> would not be treated specially by io:lines(), I
> assume.

If your file is not huge, you can read (and decode) it all at once:

  filep = lpeg.Ct(lpeg.Ct(record)^0)
  result = filep:match("*all"))

-- Roberto