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.5 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,STOX_REPLY_TYPE,TVD_FINGER_02 autolearn=no autolearn_force=no version=3.4.4 From: "Arie van Wingerden" Newsgroups: comp.lang.ada References: In-Reply-To: Subject: Re: Question on bounded / unbounded strings Date: Sat, 17 Sep 2016 18:35:08 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 16.4.3528.331 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331 Message-ID: Organization: Powered by cheapnews.eu Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!feeder3.usenet.farm!border03.ams.abavia.com!feeder04.abavia.com!abp002.abavia.com!news.cheapnews.eu!not-for-mail Injection-Date: Sat, 17 Sep 2016 18:35:09 +0200 Injection-Info: news.cheapnews.eu; mail-complaints-to="abuse@cheapnews.eu" Xref: news.eternal-september.org comp.lang.ada:31797 Date: 2016-09-17T18:35:08+02:00 List-Id: 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