comp.lang.ada
 help / color / mirror / Atom feed
From: "Arie van Wingerden" <xapwing@gmail.com>
Subject: Re: Question on bounded / unbounded strings
Date: Sat, 17 Sep 2016 18:35:08 +0200
Date: 2016-09-17T18:35:08+02:00	[thread overview]
Message-ID: <nnd$1f8ee787$61d1078d@8c983e15e4f0e3e7> (raw)
In-Reply-To: <nrc923$nth$1@dont-email.me>

Thx for the extensive review!   I'll look into it.

"Jeffrey R. Carter"  schreef in bericht news:nrc923$nth$1@dont-email.me...

On 09/14/2016 05:57 AM, Arie van Wingerden wrote:
>
>    Path   : string := ASF.Translate(AEV.Value("Path"), 
> ASMC.Lower_Case_Map);
>    Match : string := ASF.Translate(ATIO.Get_Line, ASMC.Lower_Case_Map);

You might want to look at pkg Ada.Characters.Handling, particularly the
functions To_Lower.

Ada is case insensitive, and many of us will run your code through a 
formatter
to make it look like the code we're familiar with, converting identifiers to
Initial_Caps, and changing CamelCase into difficult to read things like
Findmatch. The recommended practice for Ada is to

>    procedure FindMatch (Match : in string; Path : in string; StartPos : in
> positive; Len : in natural) is
>        EndPos : positive;
>    begin
>        if Len > 0 then  -- Ignore case of an unnecessary semi colon

This test is unnecessary. If Len = 0, Endpos = Startpos - 1, and Startpos ..
Endpos is a null range. Any array sliced with a null range yields a 
zero-length
slice; in the case of String, the null string (""). Index will always return 
0
if Source is null and Pattern is not.

>            EndPos := StartPos + Len - 1;
>            if ASF.Index(Source => Path(StartPos .. EndPos), Pattern => 
> Match) >
> 0 then
>                ATIO.Put_Line(Path(StartPos .. EndPos));
>            end if;
>        end if;
>    end FindMatch;
>
>    procedure Match_Path (Match : in string; Path : in string) is
>        StartPos : positive := 1;
>        Len   : natural  := 0;
>    begin
>        for I in Path'Range loop
>            if Path(I) = ';' then

You can use index to find semi-colons in Path

   Index (Path, ";")

>                FindMatch(Match, Path, StartPos, Len);

Note that you're passing Path and Startpos to Findmatch, which uses Startpos 
as
an index into Path. The first time you do this, Startpos = 1. In other 
words,
you're assuming that 1 is a valid index for Path. While this may always be 
true
for this program, if you need to do something similar in another situation, 
you
might reuse this code, but pass a value for Path for which it is not true. 
It
would be better to initialize Startpos to Path'First.

Rather than calculate Endpos and slice Path in Findmatch, why not pass the 
slice
of Path

   procedure Findmatch (Match : in String; Path : in String);

   Findmatch (Match => Match, Path => Path (Startpos .. Startpos + Len - 
1) );

? As noted above, passing a null string for Path will not be a problem.

If Path doesn't contain ';', your program does nothing. If Path doesn't end 
with
';', the part of Path from the last semi-colon to the end won't be checked. 
What
should it do if Match is null?

I suspect this could be implemented more simply and clearly (and correctly)
using Index for the ';' as well as for Match.

-- 
Jeff Carter
"Since I strongly believe that overpopulation is by
far the greatest problem in the world, this [Soylent
Green] would be my only message movie."
Charleton Heston
123 


  reply	other threads:[~2016-09-17 16:35 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  8:46 Question on bounded / unbounded strings Arie van Wingerden
2016-09-13  9:04 ` Dmitry A. Kazakov
2016-09-22  2:10   ` John Smith
2016-09-22  7:24     ` Dmitry A. Kazakov
2016-09-22  9:01       ` J-P. Rosen
2016-09-22  9:53         ` Dmitry A. Kazakov
2016-09-22 10:58           ` G.B.
2016-09-22 12:05             ` Dmitry A. Kazakov
2016-09-22 14:14               ` G.B.
2016-09-22 17:18                 ` Dmitry A. Kazakov
2016-09-22 11:08           ` J-P. Rosen
2016-09-22 12:05             ` Dmitry A. Kazakov
2016-09-22 13:18           ` Maciej Sobczak
2016-09-22 13:52             ` Dmitry A. Kazakov
2016-09-22 14:51               ` Maciej Sobczak
2016-09-22 17:13                 ` Dmitry A. Kazakov
2016-09-23  5:50                   ` Maciej Sobczak
2016-09-23  6:36                     ` Simon Wright
2016-09-23  7:48                       ` Dmitry A. Kazakov
2016-09-28 20:55                     ` Randy Brukardt
2016-09-23 23:58       ` John Smith
2016-09-24  7:52         ` Dmitry A. Kazakov
2016-09-24 16:25           ` John Smith
2016-09-24 17:44             ` Dmitry A. Kazakov
2016-09-24 18:33               ` John Smith
2016-09-24 18:37               ` John Smith
2016-09-24 18:59               ` John Smith
2016-09-25  8:50                 ` Dmitry A. Kazakov
2016-09-25 23:35                   ` brbarkstrom
2016-09-26  7:28                     ` Dmitry A. Kazakov
2016-09-26 12:39                       ` brbarkstrom
2016-09-28 21:09             ` Randy Brukardt
2016-09-30  7:59               ` Björn Lundin
2016-09-13  9:35 ` gautier_niouzes
2016-09-13 10:41 ` Alejandro R. Mosteo
2016-09-13 17:41 ` Jeffrey R. Carter
2016-09-13 17:59 ` Björn Lundin
2016-09-14 11:23 ` Arie van Wingerden
2016-09-14 12:26   ` Arie van Wingerden
2016-09-14 12:28   ` Arie van Wingerden
2016-09-14 12:57 ` Arie van Wingerden
2016-09-14 19:39   ` Jeffrey R. Carter
2016-09-17 16:35     ` Arie van Wingerden [this message]
2016-09-16 14:43 ` Olivier Henley
2016-09-17 16:35   ` Arie van Wingerden
replies disabled

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