Re: csv (comma separated value) file

2009-08-03 Thread Tristan Van Berkom
On Mon, Aug 3, 2009 at 12:03 PM, Andrea Zagli wrote:
> i didn't find nothing about to manage (read/write) csv files with glib
>
> do you know about something that i didn't find?
>

Currently its pretty easy using g_file_get_contents()/g_strsplit() if you
can have it all in ram, or using GIO and again, g_strsplit() on a per line
basis if you need to stream it.

Cheers,
 -Tristan
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Andrea Zagli

Il giorno lun 03 ago 2009 18:45:28 CEST, Tristan Van Berkom ha scritto:

On Mon, Aug 3, 2009 at 12:03 PM, Andrea Zagli wrote:

i didn't find nothing about to manage (read/write) csv files with glib

do you know about something that i didn't find?


Currently its pretty easy using g_file_get_contents()/g_strsplit() if you
can have it all in ram, or using GIO and again, g_strsplit() on a per line
basis if you need to stream it.


yet in fact i developed like this for a very small project. but i  
wanted to recycle the code by putting/found it in a library


and with a more accurate parsing; for example i cannot split by ","  
beacause "," can be inside string fields


then i thought to make a more accurate function with some parameters  
(ex. the character separating the fields, if the first line of the  
file are the names of the fields, etc.)


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Paolo Bacchilega

Tristan Van Berkom ha scritto:

On Mon, Aug 3, 2009 at 12:03 PM, Andrea Zagli wrote:
  

i didn't find nothing about to manage (read/write) csv files with glib

do you know about something that i didn't find?




Currently its pretty easy using g_file_get_contents()/g_strsplit() if you
can have it all in ram, or using GIO and again, g_strsplit() on a per line
basis if you need to stream it.

Cheers,
 -Tristan
  

it's not so easy, for example the following csv file:

"a;b";c

has only two columns, you cannot handle this case with a simple 
g_strsplit call


- Paolo


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Liam R E Quin
On Mon, 2009-08-03 at 12:45 -0400, Tristan Van Berkom wrote:
[...]
> Currently its pretty easy using g_file_get_contents()/g_strsplit() 

CSV files are not just comma separated, and in some cases can have
column headers and other metadata.  There's also escaping.

a,b,c\d,e
a,b,"c,d",e
a;b;c,d;e

You also have to deal with differing line ending conventions.

It's enough of a mess that both MS Office and most other
office programs today seem o use XML instead :-)

Probably gnumeric has code for this, though.

Liam


-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Tristan Van Berkom
On Mon, Aug 3, 2009 at 1:21 PM, Liam R E Quin wrote:
> On Mon, 2009-08-03 at 12:45 -0400, Tristan Van Berkom wrote:
> [...]
>> Currently its pretty easy using g_file_get_contents()/g_strsplit()
>
> CSV files are not just comma separated, and in some cases can have
> column headers and other metadata.  There's also escaping.
>
> a,b,c\d,e
> a,b,"c,d",e
> a;b;c,d;e
>

I see that was an uneducated comment on my part ;-)
(I have been doing alot of *simple* csv parsing with glib lately
that doesnt have these kind of requirements).

Sorry for the noise ;-)

Dont have much of an opinion if it should be in glib, we have
GKeyFile wich does similar high-levelish stuff already so it
might be a suitable addition.

Cheers,
  -Tristan

(interestingly my own use-case, would be a mix of both - a
fixed length keyfile like header, with variable length trailing
csv data).


> You also have to deal with differing line ending conventions.
>
> It's enough of a mess that both MS Office and most other
> office programs today seem o use XML instead :-)
>
> Probably gnumeric has code for this, though.
>
> Liam
>
>
> --
> Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
> Pictures from old books: http://fromoldbooks.org/
> Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
>
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Joshua Lock
Hi

2009/8/3 Andrea Zagli :
> i didn't find nothing about to manage (read/write) csv files with glib
>
> do you know about something that i didn't find?

GSF (GNOME Structured File Library)[1], which Gnumeric uses, does CSV:

http://library.gnome.org/devel/gsf/stable/gsf-Text.html

>
> otherwise i might develop it

1. http://library.gnome.org/devel/gsf/stable/index.html

Cheers,
Joshua
-- 
Joshua Lock
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Liam R E Quin
On Mon, 2009-08-03 at 14:23 -0400, Tristan Van Berkom wrote:
> On Mon, Aug 3, 2009 at 1:21 PM, Liam R E Quin wrote:
> > On Mon, 2009-08-03 at 12:45 -0400, Tristan Van Berkom wrote:
[...]
> I see that was an uneducated comment on my part ;-)
My reply wasn't meant as a criticism, hope it didn't appear this.

[...]

> Dont have much of an opinion if it should be in glib, we have
> GKeyFile wich does similar high-levelish stuff already so it
> might be a suitable addition.

I'd rather steer people towards XML for new stuff, and for
old stuff, maybe a csv library split off from gnumeric
might be possible?

Liam




-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-03 Thread Andrea Zagli

Il giorno lun 03 ago 2009 18:03:43 CEST, Andrea Zagli ha scritto:

i didn't find nothing about to manage (read/write) csv files with glib

do you know about something that i didn't find?

otherwise i might develop it


i found that libgda have a csv parser [1]

i'll try in the next few days

[1]  
http://library.gnome.org/devel/libgda/stable/GdaDataModel.html#gda-data-model-import-from-file


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: csv (comma separated value) file

2009-08-04 Thread Nicola Fragale

Il 04/08/2009 08:59, Andrea Zagli ha scritto:

Il giorno lun 03 ago 2009 18:03:43 CEST, Andrea Zagli ha scritto:

i didn't find nothing about to manage (read/write) csv files with glib

do you know about something that i didn't find?

otherwise i might develop it


i found that libgda have a csv parser [1]

i'll try in the next few days


libral, the rubrica's engine (http://rubrica.berlios.de) has a csv parser.
It is implemented as a gobject class, loaded at runtime as needed, by
libral.




[1] 
http://library.gnome.org/devel/libgda/stable/GdaDataModel.html#gda-data-model-import-from-file 



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




--
  Nicola Fragale
   Software Engineer
 nicolafrag...@gmail.com
-=-=-=-=-=-=-=-=-=-=-=-=-


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: csv (comma separated value) file

2009-08-24 Thread Murray Cumming
On Tue, 2009-08-04 at 11:49 +0200, Nicola Fragale wrote:
> Il 04/08/2009 08:59, Andrea Zagli ha scritto:
> > Il giorno lun 03 ago 2009 18:03:43 CEST, Andrea Zagli ha scritto:
> >> i didn't find nothing about to manage (read/write) csv files with glib
> >>
> >> do you know about something that i didn't find?
> >>
> >> otherwise i might develop it
> >
> > i found that libgda have a csv parser [1]
> >
> > i'll try in the next few days
> 
> libral, the rubrica's engine (http://rubrica.berlios.de) has a csv parser.
> It is implemented as a gobject class, loaded at runtime as needed, by
> libral.

There's also a GdaDataModel for this: GdaDataModelImport. Even if you
aren't using any database ideas, I guess you could use that API to get
the data and iterate over it.
http://library.gnome.org/devel/libgda/3.99/GdaDataModelImport.html

I don't use it in Glom just because it doesn't do progressive reading -
it reads all the data at once.

-- 
murr...@murrayc.com
www.murrayc.com
www.openismus.com

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list