comp.lang.ada
 help / color / mirror / Atom feed
* CSV package in Ada
@ 2007-03-24 18:57 Franz Kruse
  2007-03-24 19:44 ` Ludovic Brenta
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Franz Kruse @ 2007-03-24 18:57 UTC (permalink / raw)


Does somebody know of an Ada package/library that can read and write CSV 
encoded text?

Thanks for hints

Franz




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSV package in Ada
  2007-03-24 18:57 CSV package in Ada Franz Kruse
@ 2007-03-24 19:44 ` Ludovic Brenta
  2007-03-25  8:41 ` Dmitry A. Kazakov
  2007-03-26  8:40 ` Jean-Pierre Rosen
  2 siblings, 0 replies; 5+ messages in thread
From: Ludovic Brenta @ 2007-03-24 19:44 UTC (permalink / raw)


Franz Kruse writes:
> Does somebody know of an Ada package/library that can read and write
> CSV encoded text?

Look at OpenToken (in Debian, package libopentoken-dev), it has a
package named Token.CSV_Field.

-- 
Ludovic Brenta.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSV package in Ada
  2007-03-24 18:57 CSV package in Ada Franz Kruse
  2007-03-24 19:44 ` Ludovic Brenta
@ 2007-03-25  8:41 ` Dmitry A. Kazakov
  2007-03-25 11:17   ` Pascal Obry
  2007-03-26  8:40 ` Jean-Pierre Rosen
  2 siblings, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2007-03-25  8:41 UTC (permalink / raw)


On Sat, 24 Mar 2007 19:57:59 +0100, Franz Kruse wrote:

> Does somebody know of an Ada package/library that can read and write CSV 
> encoded text?

CSV = comma-separated values?

   http://www.dmitry-kazakov.de/ada/strings_edit.htm

which can read and write numbers and quoted strings skipping or placing
separators between them. The procedures that take something from the string
are named Get, the procedures that put something are named Put. When
reading a file, you read it line by line. For each line you set the cursor
(the string index) to the first character of and then call Get for each
field. To skip spaces and tabs another Get is called. Each call to a Get
advances the cursor until the whole line is done. Then you read the next
line. Writing is similar, you use Put for the line (string buffer) and
after the last field has been written, the buffer slice
(Line'First..Cursor-1) is sent the file.

For dealing with text literals (non-quoted strings) you can use tables:

   http://www.dmitry-kazakov.de/ada/tables.htm

a table will define the set of literals like (Red, Blue, Green) of a field.
The table can be matched against the string the same way the Get programs
from Strings_Edit do. The table Get finds a token and skips it in the
string returning the value associated with the token.

If you need dimensioned values in the fields, see

   http://www.dmitry-kazakov.de/ada/units.htm

which supports the same technique of Get/Put.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSV package in Ada
  2007-03-25  8:41 ` Dmitry A. Kazakov
@ 2007-03-25 11:17   ` Pascal Obry
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2007-03-25 11:17 UTC (permalink / raw)
  To: mailbox

Dmitry A. Kazakov a �crit :
> On Sat, 24 Mar 2007 19:57:59 +0100, Franz Kruse wrote:
> 
>> Does somebody know of an Ada package/library that can read and write CSV 
>> encoded text?
> 
> CSV = comma-separated values?

You can also use the GNAT.AWK package. Quite handy for this kind of
work. Or GNAT.String_Split if the string to parse is already in memory.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: CSV package in Ada
  2007-03-24 18:57 CSV package in Ada Franz Kruse
  2007-03-24 19:44 ` Ludovic Brenta
  2007-03-25  8:41 ` Dmitry A. Kazakov
@ 2007-03-26  8:40 ` Jean-Pierre Rosen
  2 siblings, 0 replies; 5+ messages in thread
From: Jean-Pierre Rosen @ 2007-03-26  8:40 UTC (permalink / raw)


Franz Kruse a ï¿œcrit :
> Does somebody know of an Ada package/library that can read and write CSV 
> encoded text?
> 
> Thanks for hints
> 
I have a little package that helps me reading CSV files (writing is 
really not a problem). It parses the string into "fields", and helps you 
add/remove quotes from quoted fields.

I'll send it to you by private mail. If anyone wants it, just write to me.

I didn't even bother to put a copyright on it (it's really small stuff).
Well, consider that I hereby declare it to be in the public domain :-)
-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-26  8:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-24 18:57 CSV package in Ada Franz Kruse
2007-03-24 19:44 ` Ludovic Brenta
2007-03-25  8:41 ` Dmitry A. Kazakov
2007-03-25 11:17   ` Pascal Obry
2007-03-26  8:40 ` Jean-Pierre Rosen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox