From: Dale Stanbrough <MrNoSpam@bigpoop.net.au>
Subject: Re: reading a text file into a string
Date: Mon, 19 Jul 2004 08:07:46 GMT
Date: 2004-07-19T08:07:46+00:00 [thread overview]
Message-ID: <MrNoSpam-C3D3BB.18074619072004@news-server.bigpond.net.au> (raw)
In-Reply-To: fOednXzORfHlE2Xd4p2dnA@comcast.com
Robert I. Eachus wrote:
>
> For this reason, I find myself contructing or using a Get_Line FUNCTION
> inside a loop and a declare block:
>
> while not End_of_Line(Somefile) loop
> declare
> Buffer: String := Get_Line(Somefile);
> begin
> -- process buffer
> exception
> ...
> end;
> end loop;
I use a generic procedure that has a process procedure as a parameter.
It gets called with each line of the string...
-- Apply the procedure Process to each line of the file
-- This allows for very simple file processing, with all of the
-- control bits (not much really) hidden away.
--
-- Each line is read from the file, and then passed to the
-- procedure
-- The maximum line size for the file is 1000 chars.
--
-- Typical use is
--
-- with Ada.Text_IO; use Ada.Text_IO;
-- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
--
-- with Process_File;
--
-- procedure Count_Chars is
--
-- Count : Natural := 0;
--
-- procedure Count_Letters (Item : String) is
-- begin
-- Count := Count + Item'Length;
-- end;
--
-- procedure Count_Em is
-- new Process_File (Process => Count_Letters);
-- begin
-- Count_Em (<Somefilename>);
-- Put ("There are ..."); Put (Count); Put (" characters");
-- end;
--
generic
with procedure Process (Line : String);
Max_Line_Size : Positive := 1000;
-- The maximum number of characters on any one line
procedure Process_File (Filename : String);
-----------------------------------------------------
it presumes a maximum line length, which is not so great, but
is otherwise a very convenient generic.
Dale
--
dstanbro@spam.o.matic.bigpond.net.au
next prev parent reply other threads:[~2004-07-19 8:07 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-15 17:27 reading a text file into a string zork
2004-07-15 17:49 ` Marius Amado Alves
2004-07-15 19:57 ` Nick Roberts
2004-07-15 17:59 ` Marius Amado Alves
2004-07-15 19:18 ` Nick Roberts
2004-07-15 19:18 ` Nick Roberts
2004-07-15 20:02 ` Nick Roberts
2004-07-16 1:23 ` Jeffrey Carter
2004-07-16 2:20 ` Steve
2004-07-16 2:26 ` Steve
2004-07-16 16:16 ` Jeffrey Carter
2004-07-16 17:45 ` Nick Roberts
2004-07-16 21:19 ` Randy Brukardt
2004-07-17 2:27 ` Robert I. Eachus
2004-07-17 11:31 ` Mats Weber
2004-07-17 15:52 ` Robert I. Eachus
2004-07-17 22:38 ` Jeffrey Carter
2004-07-18 13:44 ` zork
2004-07-19 8:07 ` Dale Stanbrough [this message]
2004-07-19 8:58 ` Martin Dowie
2004-07-21 0:17 ` Robert I. Eachus
2004-07-21 21:39 ` Randy Brukardt
2004-07-22 22:34 ` Robert I. Eachus
2004-07-23 0:49 ` Randy Brukardt
2004-07-23 21:56 ` Nick Roberts
2004-07-24 0:34 ` tmoran
2004-07-24 1:16 ` Nick Roberts
2004-07-24 1:42 ` Randy Brukardt
2004-07-24 15:14 ` Nick Roberts
2004-07-26 23:48 ` Randy Brukardt
2004-07-27 12:08 ` Nick Roberts
2004-07-27 23:24 ` Robert I. Eachus
2004-07-29 0:55 ` Randy Brukardt
2004-07-29 0:53 ` Randy Brukardt
2004-07-29 7:25 ` Martin Dowie
2004-07-29 20:08 ` Robert I. Eachus
2004-07-30 0:14 ` tmoran
2004-07-24 2:56 ` Robert I. Eachus
2004-07-19 11:51 ` Ada2005 (was " Peter Hermann
2004-07-19 12:51 ` Dmitry A. Kazakov
2004-07-19 13:01 ` Nick Roberts
2004-07-19 13:35 ` Martin Dowie
2004-07-19 17:22 ` Nick Roberts
2004-07-19 23:50 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox