comp.lang.ada
 help / color / mirror / Atom feed
From: David Trudgett <wpower@zeta.org.au.nospamplease>
Subject: Re: String filtering
Date: Wed, 28 Sep 2005 20:39:44 +1000
Date: 2005-09-28T20:39:44+10:00	[thread overview]
Message-ID: <m37jd1qxvz.fsf@rr.trudgett> (raw)
In-Reply-To: 1gdgwjo7aini9.1qzlnlpq5gsa$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Wed, 28 Sep 2005 10:06:44 +1000, David Trudgett wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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




  reply	other threads:[~2005-09-28 10:39 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-27  6:27 String filtering David Trudgett
2005-09-27  7:38 ` Jacob Sparre Andersen
2005-09-27  9:13   ` David Trudgett
2005-09-27  9:49     ` Dmitry A. Kazakov
2005-09-27 11:01       ` Martin Dowie
2005-09-27 11:12         ` Martin Dowie
2005-09-27 12:54           ` Dmitry A. Kazakov
2005-09-27 13:42             ` Martin Dowie
2005-09-27 14:24               ` Dmitry A. Kazakov
2005-09-28  0:06                 ` David Trudgett
2005-09-28  8:15                   ` Dmitry A. Kazakov
2005-09-28 10:39                     ` David Trudgett [this message]
2005-09-28 20:55                       ` Simon Wright
2005-09-28 21:53                         ` Martin Dowie
2005-09-28  9:08                   ` Jacob Sparre Andersen
2005-09-28  9:54                     ` David Trudgett
2005-09-29 14:05                       ` Georg Bauhaus
2005-10-01 19:02                         ` tmoran
2005-10-02  6:38                           ` David Trudgett
2005-10-02 14:11                             ` Martin Dowie
2005-10-02 22:40                               ` David Trudgett
2005-10-03  5:56                                 ` Martin Dowie
2005-10-03 10:33                           ` Georg Bauhaus
2005-09-28 18:21                   ` Jeffrey R. Carter
2005-09-28 21:00                   ` Simon Wright
2005-09-27 11:22         ` David Trudgett
2005-09-27 11:15       ` David Trudgett
2005-09-27 13:21         ` Dmitry A. Kazakov
2005-09-27 13:43           ` Martin Dowie
2005-09-28  0:51           ` David Trudgett
2005-09-28 12:02             ` Dmitry A. Kazakov
2005-09-28 13:25             ` Marc A. Criley
2005-09-29 22:42           ` Randy Brukardt
2005-09-30 17:54             ` Robert A Duff
2005-10-02  6:57               ` Steve Whalen
2005-10-02 14:14                 ` Martin Dowie
2005-10-03  1:21                 ` Robert A Duff
2005-10-03  7:44                   ` Jacob Sparre Andersen
2005-10-03  8:56                     ` Dmitry A. Kazakov
2005-10-03  9:25                       ` Jean-Pierre Rosen
2005-10-03 20:17                         ` Ada Notation Jeffrey R. Carter
2005-10-03 20:41                           ` Georg Bauhaus
2005-10-05 17:16                             ` Andre
2005-10-05 18:23                               ` Ludovic Brenta
2005-10-05 18:24                               ` Jeffrey R. Carter
2005-10-04 15:13                           ` brian.b.mcguinness
2005-10-04 17:00                     ` String filtering Robert A Duff
2005-10-05  8:19                       ` Jean-Pierre Rosen
2005-10-05 11:25                         ` Robert A Duff
2005-10-04 19:47                     ` Björn Persson
2005-10-05 14:14                       ` Dmitry A. Kazakov
2005-10-03 10:06                   ` Steve Whalen
2005-10-03 17:43                   ` tmoran
2005-10-03 17:59                     ` Robert A Duff
2005-10-05 23:04                       ` Randy Brukardt
2005-09-27 13:52         ` Jacob Sparre Andersen
2005-09-28  1:01           ` David Trudgett
2005-09-28  1:50             ` David Trudgett
2005-09-27 14:08         ` Georg Bauhaus
2005-09-27 14:09         ` Marc A. Criley
2005-09-28  1:09           ` David Trudgett
2005-09-28 21:09           ` Simon Wright
2005-09-27 17:59         ` tmoran
2005-09-28  1:20           ` David Trudgett
2005-09-27 17:47     ` Jeffrey R. Carter
2005-09-28  1:29       ` David Trudgett
2005-09-28 18:32         ` Jeffrey R. Carter
2005-09-27  7:41 ` tmoran
2005-09-27  9:17   ` David Trudgett
2005-09-28  1:54 ` Steve
2005-09-28  2:20   ` David Trudgett
replies disabled

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