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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f802583e5c84fa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news1.optus.net.au!optus!newsfeeder.syd.optusnet.com.au!news.optusnet.com.au!newsfeed.pacific.net.au!nasal.pacific.net.au!not-for-mail Newsgroups: comp.lang.ada Subject: Re: String filtering From: David Trudgett Organization: Very little? References: <1j92wa9843ylq.16j89wuqatbaj$.dlg@40tude.net> <433924a2$1_1@glkas0286.greenlnk.net> <43392732$1_1@glkas0286.greenlnk.net> <1jd30obyohnp6$.41tz3funikly.dlg@40tude.net> <43394a3e$1_1@glkas0286.greenlnk.net> <1gdgwjo7aini9.1qzlnlpq5gsa$.dlg@40tude.net> Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:Yea0+XrCxVXi1ust5vwhyXAGLvs= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 28 Sep 2005 20:39:44 +1000 NNTP-Posting-Host: 61.8.39.213 X-Complaints-To: news@pacific.net.au X-Trace: nasal.pacific.net.au 1127904263 61.8.39.213 (Wed, 28 Sep 2005 20:44:23 EST) NNTP-Posting-Date: Wed, 28 Sep 2005 20:44:23 EST Xref: g2news1.google.com comp.lang.ada:5232 Date: 2005-09-28T20:39:44+10:00 List-Id: "Dmitry A. Kazakov" writes: > On Wed, 28 Sep 2005 10:06:44 +1000, David Trudgett wrote: > >> "Dmitry A. Kazakov" writes: >> >>> On Tue, 27 Sep 2005 14:42:02 +0100, Martin Dowie wrote: >>>> 2nd sentence of ARM 95 A.4.5 (76) reads: >>>> >>>> "The function To_Unbounded_String(Length : in Natural) >>>> returns an Unbounded_String that represents an uninitialized >>>> String whose length is Length." >>> >>> Ah, now I see what you meant! >> >> Yep, that's what I meant, too. > > No. What Martin meant is that: > > X : Unbounded_String := To_Unbounded_String (Count); > > is filled with rubbish Yes, that's what I meant, too. There was obviously a language problem happening there, so let's go on to something else, hey? :-) > > What I meant is that: > > X : Unbounded_String; > > is an empty string, being formally uninitialized. Looking back at your original message, it is possible to see how you meant your words to be taken. However, the way you said it was far from clear, and at least two people (myself included) understood your statement differently. You could have better said something like: "And this line would then become unnecessary." > You can imagine it as Unbounded_Strings having a default constructor > setting them empty. Thanks for pointing that out, by the way, because I wasn't sure initially. I'm loathe, however, to depend upon default initialisation, even when it's specified in a standard. >> function Strip_Non_Alphanumeric >> (Str : in Unbounded_String) return Unbounded_String >> is >> Dest_Size : Natural := Count(Str, Alpha_Num_Space_Set); >> New_Str : Unbounded_String := Null_Unbounded_String; > > You don't need initialization here. I don't need it, that's true, but I prefer to be explicit about it. I might change my mind about that when I'm more experienced in Ada. > Or you can do with Dest_Size. The > parameter of To_Unbounded_String is a Natural. > >> Dest_Char : Natural := 0; >> begin >> if Dest_Size > 0 then > > You don't need this if. Ada's loops are safe for zero-run. Its purpose is not to avoid a zero run, though. The test allows an entire repeat scan of the source string to be avoided in the case that all of the source characters are not alphanumeric. The initialisation of New_Str to a null string means that it is ready to return immediately without code execution passing through the loop. This avoids the situation of returning an unitialised unbounded_string when all source string characters are non-alphanumeric. >> function Strip_Non_Alphanumeric >> (Str : in String) return String >> is >> New_Str : String(1 .. Count(Str, Alpha_Num_Space_Set)); > > You also can do instead: > > New_Str : String(1 .. Length (Str)); Yes, an interesting idea, combined with the sliced return. > > here you do: > > return New_Str (1..Dest_Char); > > Ada strings has slices! Interesting. I hadn't considered that! David -- David Trudgett http://www.zeta.org.au/~wpower/ Whoever publicly profanes the Reich or one of the states incorporated into it, its constitution, colors or flag or the German armed forces, or maliciously and with premeditation exposes them to contempt, shall be punished by imprisonment. -- Statutory Criminal Law of Germany 19 December 1932, RGB 1-1 The Congress and the States shall have the power to prohibit the act of desecration of the flag of the United States and to set criminal penalties for that act. -- Proposed Amendment to Constitution 22 June 1989, H.J. Res. 305