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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Question on bounded / unbounded strings Date: Tue, 13 Sep 2016 11:04:43 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: vZYCW951TbFitc4GdEwQJg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:31765 Date: 2016-09-13T11:04:43+02:00 List-Id: On 13/09/2016 10:46, Arie van Wingerden wrote: > Hi, > > for a long time I've been interested in Ada but hadn't played with it. > > Now I bit the bullet and I am trying to create a small (Windows) program > that: > 1) reads a string from STDIN (yet to do) > 2) fetches the contents of the PATH environment variable (done) > 3) splits that content in individual paths (???) > 4) tries to match the inputted string with part of each path (to do) > 5) outputs only the matched paths (to do) > > I found out the hard way that Ada is very strict about bounded versus > unbounded strings. > So I had to convert the output of 2) to an unbounded string, because I > could not know it's length in advance. > > Now I am a bit stuck splitting the string of paths; > I use GNAT.String_Split.Create, but it needs a (bounded) String as input. > However, I only have an unbounded string. > > QUESTION: How can I convert an unbounded string to a standard (bounded) > string? Don't use either. For the thing you described (and for almost all cases) standard String is a better, easier and safer choice. Bounded strings are useless altogether. Unbounded string have very limited use. P.S. Splitting/tokenization is just a wrong pattern for string processing. You need not split strings at all. You just scan the string from delimiter to delimiter marking beginning and end of the token and then pass the substring further, e.g. building an ordered set of [normalized] paths or directly matching them as they appear. It is simpler, cleaner, safer and far more effective. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de