 |
Forums |
Admin Start New Thread
By: James Gray
RE: :row_sep not taken into account ??? [ reply ] 2010-06-10 16:03
|
It should definitely work with an unquoted \r\n. If does when I test locally:
>> require "rubygems"
=> true
>> require "faster_csv"
=> true
>> FCSV.parse("a,b,c\r\n1,2,3\r\n", :headers => true, :encoding => "U").to_a
=> [["a", "b", "c"], ["1", "2", "3"]]
I see you are setting the quote_char and col_sep. What's in those variables? I would recommend removing all settings where the defaults work, to decrease chances of introducing an incompatibility.
James Edward Gray II
|
By: Benjamin BAROUKH
RE: :row_sep not taken into account ??? [ reply ] 2010-06-10 15:10
|
Hi,
I tried passing a UTF8 encoded file and specified "U" for the encoding parameter in FasterCSV.
I noticed sometimes the messages says:
FasterCSV::MalformedCSVError (Unquoted fields do not allow \r or \n (line 1).). This is when my last header does not have quotes. When it does, fasterCSV just throws MalformedCSVError without detail.
The only \r\n in the file are the ends of row.
By the way, does fasterCSV supports ANSI (default windows encoding) in any way? I have tried and it seems fine (with \n EoL though).
Thanks.
|
By: Benjamin BAROUKH
:row_sep not taken into account ??? [ reply ] 2010-06-10 10:39
|
Hi,
I am using FasterCSV to parse a CSV file from the disk in a Rails app.
Here is the code:
row_sep = "\r\n"
FasterCSV.foreach(tmpfile.path, {:headers=>true, :encoding=>encoding, :quote_char=>wrapper, :col_sep=>splitter, :row_sep=>row_sep}) do |row|
@samples[i] = row
i += 1
if i >= sample_count
break
end
end
It seems that whatever I input for "row_sep", I tried "\r", "\r\n", "\\r\\n", and whatever the value, the only files which are accepted are Linux EoF based files (\n).
The error I get in the console is always:
FasterCSV::MalformedCSVError (FasterCSV::MalformedCSVError):
lib/faster_csv.rb:1616:in `shift'
lib/faster_csv.rb:1608:in `each'
lib/faster_csv.rb:1608:in `shift'
lib/faster_csv.rb:1575:in `loop'
lib/faster_csv.rb:1575:in `shift'
lib/faster_csv.rb:1520:in `each'
lib/faster_csv.rb:1024:in `foreach'
lib/faster_csv.rb:1198:in `open'
lib/faster_csv.rb:1023:in `foreach'
vendor/plugins/redmine_importer/app/controllers/importer_controller.rb:52:in `match'
Any ideas?
Thanks for your help.
|
|
 |