comp.lang.ada
 help / color / mirror / Atom feed
From: "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr>
Subject: Re: Strings and reading from a file
Date: 1999/05/14
Date: 1999-05-14T11:02:35+00:00	[thread overview]
Message-ID: <7hgvsb$fgj$1@wanadoo.fr> (raw)
In-Reply-To: 373B93FC.9E89E2C2@Botton.com


David Botton a �crit dans le message <373B93FC.9E89E2C2@Botton.com>...
>May I include your code on The Ada Source Code Treasury at
AdaPower.com?
>
>David Botton
>
>
>"Martin C. Carlisle" wrote:
>>
>> I can't imagine!  Probably something more like:
>>
>> function Next_Line(File : in Ada.Text_IO.File_Type :=
>>    Ada.Text_Io.Standard_Input) return String is
>>    Answer : String(1..256);
>>    Last   : Natural;
>> begin
>>    Ada.Text_IO.Get_Line(File => File,
>>       Item => Answer,
>>       Last => Last);
>>    if Last = Answer'Last then
>>       return Answer & Next_Line;
>>    else
>>       return Answer(1..Last);
>>    end if;
>> end Next_Line;
>>
While were at improving it, what about:
function Next_Line
  (File : in Ada.Text_IO.File_Type :=  Ada.Text_Io.Standard_Input;
   Guessed_Length : Positive := 256) return String is
   Answer : String(1..Guessed_Length);
   Last   : Natural;
begin
   Ada.Text_IO.Get_Line(File => File,
      Item => Answer,
      Last => Last);
   if Last = Answer'Last then
      return Answer & Next_Line (File, 2*Guessed_Length);
   else
      return Answer(1..Last);
   end if;
end Next_Line;

This will minimize the number of recursive calls for very long lines.
(Not also that in the previous version, the recursive call to
Next_Line forgot the File argument).
---------------------------------------------------------
           J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://perso.wanadoo.fr/adalog






  parent reply	other threads:[~1999-05-14  0:00 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-12  0:00 Strings and reading from a file Cameron Hodge
1999-05-11  0:00 ` David Botton
1999-05-12  0:00 ` Gautier
1999-05-12  0:00 ` Robert Dewar
1999-05-12  0:00   ` Cameron Hodge
1999-05-12  0:00     ` David C. Hoos, Sr.
1999-05-12  0:00     ` Marin David Condic
1999-05-12  0:00       ` Tom Moran
1999-05-12  0:00         ` Marin David Condic
1999-05-13  0:00       ` jrcarter001
1999-05-13  0:00         ` dennison
1999-05-13  0:00           ` Martin C. Carlisle
1999-05-13  0:00             ` David Botton
1999-05-13  0:00               ` David Botton
1999-05-14  0:00               ` Jean-Pierre Rosen [this message]
1999-05-14  0:00                 ` Keith Thompson
1999-05-14  0:00                   ` David C. Hoos, Sr.
1999-05-14  0:00                     ` Keith Thompson
1999-05-15  0:00                       ` David C. Hoos, Sr.
1999-05-16  0:00                   ` Jean-Pierre Rosen
1999-05-13  0:00             ` Marin David Condic
1999-05-13  0:00               ` Keith Thompson
1999-05-14  0:00                 ` Pascal Obry
1999-05-13  0:00               ` Hyman Rosen
1999-05-15  0:00             ` jrcarter001
1999-06-05  0:00               ` Matthew Heaney
1999-05-12  0:00   ` dennison
replies disabled

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