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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Question on bounded / unbounded strings Date: Wed, 14 Sep 2016 12:39:51 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 14 Sep 2016 19:39:49 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="6df4b173985f7c5c043cea362c370ff7"; logging-data="24497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hPAPHJW0LiSPr0dIvxJjRG9SuSOoWGaA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:hP2IwJ/O228Z34LSXCiIPtrmrP4= Xref: news.eternal-september.org comp.lang.ada:31787 Date: 2016-09-14T12:39:51-07:00 List-Id: 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