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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,73989f41631a6beb X-Google-Attributes: gid103376,public From: Mark Griglock Subject: Re: What's the deal with "slice" in Ada.Strings.Bounded Date: 1997/07/15 Message-ID: <33CC07BB.7F52@lmco.com>#1/1 X-Deja-AN: 257084486 References: <33CBDCDF.751F5ECB@digicomp.com> Organization: Lockheed Martin Federal Systems Reply-To: mark.griglock@lmco.com Newsgroups: comp.lang.ada Date: 1997-07-15T00:00:00+00:00 List-Id: Jan Galkowski wrote: > > The package Ada.Strings.Bounded operates upon a private type > "Bounded_String". Among the other constructors and manipulators > in that package, there is an interrogator called "Slice". > > What I'm trying to figure out is how to create a Bounded_String > out of the return value from this "Slice". The type > given for the return value is the general "String". Naturally, > compilers balk at trying to specify a variable having definite > dimensions using an object which has indefinite ones. > > So, how would you suggest making a Bounded_String out of this > return value from "Slice"? In other words, how does one > write, for this case, a function > > function To_Bounded_String( Given_String : in String ) > return Bounded_String is > ... > begin > ... > end To_Bounded_String ; > > where Bounded_String has been given a fixed length by instantiating > "Generic_Bounded_Length". > The above function already exists in Generic_Bounded_Length, (it does, however, have a second parameter with a default). It is also called To_Bounded_String. For example, you could write the following specific function: package Bounded_80 is new Ada.Strings.Bounded.Generic_Bounded_Length(80); function Slice_80 (Source : in Bounded_80.Bounded_String; Low : in Positive; High : in Natural) return Bounded_80.Bounded_String is begin return Bounded_80.To_Bounded_String (Bounded_80.Slice(Source, Low, High)); end Slice_80; Or, if you needed this for all Bounded_Length strings, you can make it generic: generic with package Bounded is new Ada.Strings.Bounded.Generic_Bounded_Length(<>); function Slice (Source : in Bounded.Bounded_String; Low : in Positive; High : in Natural) return Bounded.Bounded_String; function Slice (Source : in Bounded.Bounded_String; Low : in Positive; High : in Natural) return Bounded.Bounded_String is begin return Bounded.To_Bounded_String (Bounded.Slice(Source, Low, High)); end Slice; Sorry, if I misunderstood the question...