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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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: =?UTF-8?Q?Bj=c3=b6rn_Lundin?= Newsgroups: comp.lang.ada Subject: Re: Question on bounded / unbounded strings Date: Fri, 30 Sep 2016 09:59:22 +0200 Organization: A noiseless patient Spider Message-ID: References: <11ee98f5-d373-4c72-8562-c310cc76817d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 30 Sep 2016 07:59:12 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="6a09ccc49493ecf301ef65af9aa456c7"; logging-data="31607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ksNLTIp8Bw/X//wUO5W1s" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 In-Reply-To: Cancel-Lock: sha1:KguErnZNWnQbu71qqQ6D1coWj+0= Xref: news.eternal-september.org comp.lang.ada:31949 Date: 2016-09-30T09:59:22+02:00 List-Id: On 2016-09-28 23:09, Randy Brukardt wrote: > "John Smith" wrote in message > news:e60176b6-4c61-474a-a191-b31821816004@googlegroups.com... > On Saturday, September 24, 2016 at 3:52:54 AM UTC-4, Dmitry A. Kazakov > wrote: > ... >> However, if I ever need string functionality that I'm used to in Python or >> C++, > > Ada doesn't have it (sadly). > > I used to tell people to use Unbounded_Strings, but that was before I tried > to build an application that way. (I discussed that further in a different > message in this thread). You have to revert to String in many places (which > is aggrevating [Ada 2005 did eliminate a couple of them, but it doesn't help > much], one has to look up the names of the operations beyond the most basic, > and if you are sensible use-adverse person (:-)), the names you have to use > are nasty (Ada.Strings.Unbounded.To_Unbounded_String ("Foo") -- gack!!!) > Recently I needed to process xml files, and do a bit of string manipulation with the results. I agree that Unbounded_String is clumpsy (name-wise) and that Ada.Strings.Fixed has useful operations. I ended up wrapping what I need in a new object - String_Object - with naming I know will trigger people here :-) with Ada.Strings; use Ada.Strings; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package Repository_Types is type String_Object is tagged private; procedure Set(Self : in out String_Object; What : String); procedure Reset(Self : in out String_Object); function Fix_String( Self : String_Object) return String; function UBString( Self : String_Object) return Unbounded_String; function Lower_Case( Self : String_Object) return String; function Upper_Case( Self : String_Object) return String ; function Empty_String_Object return String_Object; procedure Append(Self : in out String_Object; What : String); function Camel_Case(Self : String_Object) return String ; procedure Delete_Last_Char(Self : in out String_Object); function "<"( Left, Right : String_Object) return Boolean; function "="( Left, Right : String_Object) return Boolean; function ">"( Left, Right : String_Object) return Boolean; private type String_Object is tagged record Value , Camel_Case_Cache, Lower_Case_Cache, Upper_Case_Cache: Unbounded_String := Null_Unbounded_String; end record; end Repository_Types; To me, it turned out to be quite useful -- -- Björn