lib/faster_csv.rb in rw_fastercsv-1.5.6 vs lib/faster_csv.rb in rw_fastercsv-1.5.7
- old
+ new
@@ -831,11 +831,12 @@
:headers => false,
:return_headers => false,
:header_converters => nil,
:skip_blanks => false,
:force_quotes => false,
- :raise_exception => false}.freeze
+ :raise_exception => false,
+ :single_line => true}.freeze
#
# This method will build a drop-in replacement for many of the standard CSV
# methods. It allows you to write code like:
#
@@ -1589,13 +1590,16 @@
#
loop do
# add another read to the line
if read_line = @io.gets(@row_sep)
line += read_line
+
+ line = '' if @single_line && line.scan(Regexp.new(@quote_char)).size%2 != 0
else
return nil
end
+
# copy the line so we can chop it up in parsing
parse = line.dup
parse.sub!(@parsers[:line_end], "")
#
@@ -1802,10 +1806,11 @@
# store the parser behaviors
@skip_blanks = options.delete(:skip_blanks)
@encoding = options.delete(:encoding) # nil will use $KCODE
@field_size_limit = options.delete(:field_size_limit)
@raise_exception = options.delete(:raise_exception)
-
+ @single_line = options.delete(:single_line)
+
# prebuild Regexps for faster parsing
esc_col_sep = Regexp.escape(@col_sep)
esc_row_sep = Regexp.escape(@row_sep)
esc_quote = Regexp.escape(@quote_char)
@parsers = {