comp.lang.ada
 help / color / mirror / Atom feed
* What's the deal with "slice" in Ada.Strings.Bounded
@ 1997-07-15  0:00 Jan Galkowski
  1997-07-15  0:00 ` Mark Griglock
  1997-07-16  0:00 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: Jan Galkowski @ 1997-07-15  0:00 UTC (permalink / raw)



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".

TIA.

Ciao.

-- 
 Jan Theodore Galkowski, 
 developer, statistician,

  speaking only for myself,
  
  jan@digicomp.com 
  jtgalkowski@worldnet.att.net

  Member, 

    the American Statistical Association,
    the Union of Concerned Scientists.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the deal with "slice" in Ada.Strings.Bounded
  1997-07-15  0:00 What's the deal with "slice" in Ada.Strings.Bounded Jan Galkowski
@ 1997-07-15  0:00 ` Mark Griglock
  1997-07-16  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Griglock @ 1997-07-15  0:00 UTC (permalink / raw)



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...




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: What's the deal with "slice" in Ada.Strings.Bounded
  1997-07-15  0:00 What's the deal with "slice" in Ada.Strings.Bounded Jan Galkowski
  1997-07-15  0:00 ` Mark Griglock
@ 1997-07-16  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1997-07-16  0:00 UTC (permalink / raw)



Jan says

<<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".
>>


Well the answer to this is amazingly obvious, and no doubt lots of people
will reply with a specific answer (use To_Bounded_String), but perhaps
more useful is to describe how you could easily have found the answer
to this yourself.

If you are using a package like Bounded_String, then at least read through
the spec to see what routines are there. If you don't understand one of
them, look it up in the RM (the RM is not easy reading in general, but
Annex A is generally quite accessible).

If you do this, you will happen (almost immediately, it is right at the
front) on:

     function To_Bounded_String                                   
       (Source : in String;                                       
        Drop   : in Truncation := Error)                          
        return   Bounded_String;                                  

and you can probably guess how to use this without even needing the RM






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-07-16  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-15  0:00 What's the deal with "slice" in Ada.Strings.Bounded Jan Galkowski
1997-07-15  0:00 ` Mark Griglock
1997-07-16  0:00 ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox