From: Dave Burt Date: 2006-04-28T00:52:03+09:00 Subject: Re: Q about the FasterCSV James Edward Gray II wrote: > On Apr 27, 2006, at 10:28 AM, Dave Burt wrote: >> :leading_fields => >> /\A#{Regexp.escape(@col_sep)}+/, # for empty leading fields > > You should modify the above line too. It takes both to correctly parse > some lines: > > /\A\s*#{Regexp.escape(@col_sep)}+/ I looked at this, but I deduced from [1] that a number of fields equal to the match size are added, so (I guess) " ,, foo" would get extra leading fields: [nil, nil, nil, nil, "foo"]. So I skipped it. I'm also guessing the OP doesn't need it, anyway. > Looks good to me. Just don't hold your breath waiting on the patch... ;) Oh, I don't want the patch. It's a terrible idea! "foo, bar, 'baz'" aren't CSV, they're CASWSSV (comma and some white-space separated values). That's got to be a whole new library :) Cheers, Dave [1] faster_csv.rb lines 1114..1115: csv = if parse.sub!(@parsers[:leading_fields], "") [nil] * $&.length P.S.: There's a bug here, and not just here, I think. Maybe init_separators should raise an exception if @col_sep.size != 1, or use options[:col_sep][0,1]. It currently barfs late and in various interesting ways for multi-character values of col_sep.