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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.103.69 with SMTP id b66mr7378138ywc.14.1474510211416; Wed, 21 Sep 2016 19:10:11 -0700 (PDT) X-Received: by 10.157.51.3 with SMTP id f3mr1214026otc.4.1474510211363; Wed, 21 Sep 2016 19:10:11 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!m9no1738999qte.0!news-out.google.com!b4ni8187iti.0!nntp.google.com!u18no2885554ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 21 Sep 2016 19:10:11 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:18f:900:8350:6600:6aff:fe37:6bdc; posting-account=AvekzAoAAABj-TclKcOWQmXwA49MFPGX NNTP-Posting-Host: 2601:18f:900:8350:6600:6aff:fe37:6bdc References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <11ee98f5-d373-4c72-8562-c310cc76817d@googlegroups.com> Subject: Re: Question on bounded / unbounded strings From: John Smith Injection-Date: Thu, 22 Sep 2016 02:10:11 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:31835 Date: 2016-09-21T19:10:11-07:00 List-Id: On Tuesday, September 13, 2016 at 5:05:33 AM UTC-4, Dmitry A. Kazakov wrote: > 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 Why would you say this? I've found the ease with which you can append or manipulate unbounded strings to be very convenient. Furthermore, I don't need to worry about computing the bound of my string. >From my experience unbounded string are very easy to work with. But I genuinely am curious about your view on this and why.