comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: CSV package in Ada
Date: Sun, 25 Mar 2007 10:41:01 +0200
Date: 2007-03-25T10:40:43+02:00	[thread overview]
Message-ID: <1cys02tpeum2j$.1rndvnxqpgq66$.dlg@40tude.net> (raw)
In-Reply-To: eu3sbi$8g8$02$1@news.t-online.com

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



  parent reply	other threads:[~2007-03-25  8:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2007-03-25 11:17   ` Pascal Obry
2007-03-26  8:40 ` Jean-Pierre Rosen
replies disabled

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