# FasterCSV problem

**URL:** <https://rubytalk.org/t/fastercsv-problem/30423>\
**Category:** ruby-talk\
**Created:** [28 August 2006 20:40 UTC](https://rubytalk.org/t/fastercsv-problem/30423 "2006-08-28T20:40:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Van\_Holstyn1](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Mark\_Van\_Holstyn1](https://rubytalk.org/u/Mark_Van_Holstyn1)\
**Post date:** [28 August 2006 20:40 UTC](https://rubytalk.org/t/fastercsv-problem/30423/1 "2006-08-28T20:40:54Z")

</div>

Is there any way to make the faster CSV library parse this line?

20 6" Multibrand Pricer Insert 2 4

I know i can use the :col\_sep options to change the column separator to a  
tab, but it fails to parse this because of an unclosed quoted field. It  
seems like there should be an option to say that the fields are not quoted.

Thanks,

> **···**
>
> --  
> Mark Van Holstyn  
> [mvette13@gmail.com](mailto:mvette13@gmail.com)  
> [http://lotswholetime.com](http://lotswholetime.com)

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [28 August 2006 21:23 UTC](https://rubytalk.org/t/fastercsv-problem/30423/2 "2006-08-28T21:23:20Z")

</div>

it that's indeed the case why not simply do it yourself?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;harp:~ \> cat a.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'rubygems'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;require 'fastercsv'

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def munge line  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.gsub!(%r/"+/){|q| q.size % 2 == 0 ? q : '"' + q}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.gsub!(%r/\ \*\t\ \*/, '","')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"%s%s%s" % ['"', line, '"']  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def show line  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts line  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;munged = munge line  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts munged  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p(FCSV.parse(munged).first)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines = \<\<-lines  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6"" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6""" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6"""" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines.each{|line| show line.strip}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;harp:~ \> ruby a.rb  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"20","6""","Multibrand","Pricer","Insert","2","4"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["20", "6\"", "Multibrand", "Pricer", "Insert", "2", "4"]

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6"" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"20","6""","Multibrand","Pricer","Insert","2","4"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["20", "6\"", "Multibrand", "Pricer", "Insert", "2", "4"]

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6""" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"20","6""""","Multibrand","Pricer","Insert","2","4"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["20", "6\"\"", "Multibrand", "Pricer", "Insert", "2", "4"]

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20 6"""" Multibrand Pricer Insert 2 4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"20","6""""","Multibrand","Pricer","Insert","2","4"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["20", "6\"\"", "Multibrand", "Pricer", "Insert", "2", "4"]

if fastercsv handled \_\_all\_\_ the 'simple' exectptions is would be slow and  
complicated to maintain.

kind regards.

-a

> **···**
>
> On Tue, 29 Aug 2006, Mark Van Holstyn wrote:
> 
> > Is there any way to make the faster CSV library parse this line?
> > 
> > 20 6" Multibrand Pricer Insert 2 4
> > 
> > I know i can use the :col\_sep options to change the column separator to a  
> > tab, but it fails to parse this because of an unclosed quoted field. It  
> > seems like there should be an option to say that the fields are not quoted.
> > 
> > Thanks,
> 
> --  
> to foster inner awareness, introspection, and reasoning is more efficient than  
> meditation and prayer.  
> - h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [28 August 2006 21:25 UTC](https://rubytalk.org/t/fastercsv-problem/30423/3 "2006-08-28T21:25:24Z")

</div>

Well, if quotes aren't quoted it's not CVS and all the parser you really need is:

&nbsp;&nbsp;&nbsp;line.split("\t")

right? 😉

FasterCSV uses a very strict parser, so no it won't allow this. Sorry.

James Edward Gray II

> **···**
>
> On Aug 28, 2006, at 3:40 PM, Mark Van Holstyn wrote:
> 
> > Is there any way to make the faster CSV library parse this line?
> > 
> > 20 6" Multibrand Pricer Insert 2 4
> > 
> > I know i can use the :col\_sep options to change the column separator to a  
> > tab, but it fails to parse this because of an unclosed quoted field. It  
> > seems like there should be an option to say that the fields are not quoted.

---

<div class="post-metadata">

**Author:** ![Mark\_Van\_Holstyn1](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Mark\_Van\_Holstyn1](https://rubytalk.org/u/Mark_Van_Holstyn1)\
**Post date:** [28 August 2006 22:22 UTC](https://rubytalk.org/t/fastercsv-problem/30423/4 "2006-08-28T22:22:28Z")

</div>

I did end up cleaning the row myself. I just wondered if I was missing the  
option somewhere. The only reason I ask is because Excel/OOCalc allow you to  
say whether or not fields are surrounded by "'s. It would be a nice option.

mark

> **···**
>
> --  
> Mark Van Holstyn  
> [mvette13@gmail.com](mailto:mvette13@gmail.com)  
> [http://lotswholetime.com](http://lotswholetime.com)

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [28 August 2006 22:30 UTC](https://rubytalk.org/t/fastercsv-problem/30423/5 "2006-08-28T22:30:47Z")

</div>

I guess I'm dense today...

FasterCSV is for parsing CSV. Without quoting, we are not talking about CSV.

Can you please explain how `fields = line.split("\t")` fails you?

If there's a real need for this, I'll consider it. But right now I would implement it as the above and I hope that's not what your asking for. 😉

James Edward Gray II

> **···**
>
> On Aug 28, 2006, at 5:22 PM, Mark Van Holstyn wrote:
> 
> > I did end up cleaning the row myself. I just wondered if I was missing the  
> > option somewhere. The only reason I ask is because Excel/OOCalc allow you to  
> > say whether or not fields are surrounded by "'s. It would be a nice option.

---

<div class="post-metadata">

**Author:** ![Mark\_Van\_Holstyn1](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Mark\_Van\_Holstyn1](https://rubytalk.org/u/Mark_Van_Holstyn1)\
**Post date:** [28 August 2006 22:42 UTC](https://rubytalk.org/t/fastercsv-problem/30423/6 "2006-08-28T22:42:05Z")

</div>

> FasterCSV is for parsing CSV. Without quoting, we are not talking  
> about CSV.

Technically, yes.

Can you please explain how `fields = line.split("\t")` fails you?

This would work in my situation just fine.

If there's a real need for this, I'll consider it. But right now I

> would implement it as the above and I hope that's not what your  
> asking for. 😉

If this is something you dont thinks should be in the CSV library, because  
is it not actually "official" csv, then that is fine. I look at that file as  
being "almost" CSV (with the exception of putting "'s around fields). The  
only reason I even ran into this is because mysql outputs bad csv

mark

> **···**
>
> --  
> Mark Van Holstyn  
> mvette13@gmail.com  
> [http://lotswholetime.com](http://lotswholetime.com)

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [28 August 2006 22:57 UTC](https://rubytalk.org/t/fastercsv-problem/30423/7 "2006-08-28T22:57:57Z")

</div>

> If this is something you dont thinks should be in the CSV library, because  
> is it not actually "official" csv, then that is fine.

Well, it's more that I don't see what I can give you that split() doesn't. Hard for me to improve on that, you know? 😉

> I look at that file as  
> being "almost" CSV (with the exception of putting "'s around fields).

In proper CSV the 6" field would really be:

&nbsp;&nbsp;&nbsp;"6"""

It's pretty different. Without the quotes it's illegal to use \t, \r, and \n in fields (I assume). There's just really nothing there you need a parser for, in my opinion.

James Edward Gray II

> **···**
>
> On Aug 28, 2006, at 5:42 PM, Mark Van Holstyn wrote:
