From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,d93b7c6dd17cbc81 X-Google-Attributes: gid103376,public From: "Jean-Pierre Rosen" Subject: Re: Strings and reading from a file Date: 1999/05/14 Message-ID: <7hgvsb$fgj$1@wanadoo.fr>#1/1 X-Deja-AN: 477768509 Content-Transfer-Encoding: 8bit References: <7han2q$jkp$1@news.iinet.net.au> <37399913.BD928DD1@pwfl.com> <7hevh1$g08$1@nnrp1.deja.com> <7hf2bc$imm$1@nnrp1.deja.com> <7hf611$16i$1@cnn.Princeton.EDU> <373B93FC.9E89E2C2@Botton.com> Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2120.0 X-Complaints-To: abuse@wanadoo.fr X-Trace: wanadoo.fr 926679755 15891 164.138.70.42 (14 May 1999 11:02:35 GMT) Organization: Adalog Mime-Version: 1.0 NNTP-Posting-Date: 14 May 1999 11:02:35 GMT Newsgroups: comp.lang.ada Date: 1999-05-14T11:02:35+00:00 List-Id: 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