Project

General

Profile

Defect #7039 » csv_text_fields_eol.patch

FasterCSV change - Etienne Massip, 2011-03-26 16:34

View differences:

lib/faster_csv.rb (working copy)
# establish quoting rules
do_quote = lambda do |field|
@quote_char +
String(field).gsub(@quote_char, @quote_char * 2) +
@quote_char +
stringify_field(field).gsub(@quote_char, @quote_char * 2) +
@quote_char
end
@quote = if options.delete(:force_quotes)
......
if field.nil? # represent +nil+ fields as empty unquoted fields
""
else
field = String(field) # Stringify fields
field = stringify_field(field)
# represent empty fields as empty quoted fields
if field.empty? or
field.count("\r\n#{@col_sep}#{@quote_char}").nonzero?
......
end
end
end
# Stringify fields
def stringify_field(field)
if field.is_a?(String)
field.gsub("\r\n", "\n")
else
String(field)
end
end
# Pre-compiles parsers and stores them by name for access during reads.
def init_parsers(options)
# store the parser behaviors
(3-3/7)