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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d93b7c6dd17cbc81 X-Google-Attributes: gid103376,public From: Marin David Condic Subject: Re: Strings and reading from a file Date: 1999/05/13 Message-ID: <373B271F.EA28F9C8@pwfl.com>#1/1 X-Deja-AN: 477526831 Content-Transfer-Encoding: 7bit Sender: condicma@bogon.pwfl.com 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> Content-Type: text/plain; charset=us-ascii Organization: Pratt & Whitney Mime-Version: 1.0 Reply-To: diespammer@pwfl.com Newsgroups: comp.lang.ada Date: 1999-05-13T00:00:00+00:00 List-Id: 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; > This is a very clever and much more general solution than my original code segment. (I must confess, I've seen this idiom before.) It has the decided advantage that it will work for any length line and coupled with the Unbounded_String type makes the most "polished" answer to the original post. (If Cameron Hodge is still listening?) Obviously, it will not incur any recursion overhead for most lines, so it has efficiency working for it as well. However - enamoured as I am with the "perfect" solution that works for any case that may arise - I'd wonder if in practice it isn't a bit of overkill. In my experience with text files, most lines are less than the 80 character width of a punchcard or glass-teletype. Probably 95% of text lines are within twice that number. I can't recall ever seeing a text line (in a standard text file like what would be used for some word processing app - not a custom data file) which ever exceeded a 256 byte string. Perhaps I'll have to dig up my newly minted statistics library and hack together a little program to produce the descriptive statistics on line length from some collection of text files - just so I know what length to pick to get me to Six Sigma on the "defect rate"? Or would that constitute proof that I have way too much time on my hands? (Well at least its not as bad as the web page where someone translated the King James Version of the Bible into Pig Latin! :-) MDC -- Marin David Condic Real Time & Embedded Systems, Propulsion Systems Analysis United Technologies, Pratt & Whitney, Large Military Engines M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600 ***To reply, remove "bogon" from the domain name.*** Visit my web page at: http://www.flipag.net/mcondic