comp.lang.ada
 help / color / mirror / Atom feed
From: Wes Groleau <no.such.user@does.not.exist.com>
Subject: Re: array conversion - how to do?
Date: 1997/06/27
Date: 1997-06-27T00:00:00+00:00	[thread overview]
Message-ID: <33B3DE95.41EF@does.not.exist.com> (raw)
In-Reply-To: 5opej8$rv5$1@gonzo.sun3.iaf.nl


If I didn't misunderstand your intent, you could use 
Ada.Characters.Handling.To_Basic to eliminate most (not 
all) of the characters outside of the ASCII range, and
Ada.Characters.Handling.To_ISO_646 to convert the rest 
to something you specify.

To eliminate the non-printable characters--please note 
that Character'Val (127) is non-printable)--you could use
Ada.Strings.Fixed.Translate (in fact, you could use it for 
the whole thing).

Geert Bosch wrote:
> Here is a simple situation illustrating a problem I encountered
> in using arrays of pointers to tagged objects. I have an
> application that should only use printable ASCII characters in its
> string processing. So I declare the following:
> 
>    subtype ASCII_Character is Character
>      range Character'Val (32) .. Character'Val (127);
>    type ASCII_String is array (Positive range <>) of ASCII_Character;
> 
> Now this string is clearly convertible to the String type, since
> the components have the same type, the ASCII_Character is only
> more constrained. Thus when my application wants to output its
> ASCII_String results, it uses:
> 
>    with Ada.Text_IO; use Ada.Text_IO;
>    procedure Test is
>       Warning_Message : ASCII_String := "Warning: only use 7-bit ASCII";
>    begin
>       ...
>       Put_Line (String (Warning_Message));
>    end Test;
> 
> Although this is IMHO a solution with clear semantics, this is
> not legal Ada because of the rule that array conversions are only
> allowed between array types that have components of the same subtype.
> The workaround is both ugly and inefficient using a typical Ada
> implementation:
> 
>    procedure Put_Line (Item : in ASCII_String) is
>       Standard_String : String (Item'Range);
>    begin
>       for I in Item'Range loop
>          Standard_String (I) := Item (I);
>       end loop;
>    end Put_Line;
> 
>    ...  -- And so on for all subprograms that use strings
> 
> I could imagine why it would not be possible to convert String
> to ASCII_String, since that conversion might need time-consuming
> checks. The conversion in the example is completely safe though,
> which is statically checkable for the compiler.
> 
> Actually in my real program where I use arrays of
> access-to-classwide types it really makes sense to convert
> arrays of access B'Class to arrays of access A'Class, when
> B is an extension of A.
> 
> In some situations it is really useful to use arrays of
> (access-to) tagged types, but it is quite annoying that
> I cannot convert arrays to more general types but need
> to copy them or use Unchecked_Conversion.
> 
> Can somebody give me a reason why this limitation is
> in the language? A good work-around would also be very
> welcome.
> 
> Regards,
>    Geert

-- 
----------------------------------------------------------------------
    Wes Groleau, Hughes Defense Communications, Fort Wayne, IN USA
Senior Software Engineer - AFATDS                  Tool-smith Wanna-be
                    wwgrol AT pseserv3.fw.hac.com

Don't send advertisements to this domain unless asked!  All disk space
on fw.hac.com hosts belongs to either Hughes Defense Communications or 
the United States government.  Using email to store YOUR advertising 
on them is trespassing!
----------------------------------------------------------------------




  reply	other threads:[~1997-06-27  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-24  0:00 array conversion - how to do? Geert Bosch
1997-06-27  0:00 ` Wes Groleau [this message]
1997-06-27  0:00   ` Robert Dewar
1997-06-28  0:00     ` Geert Bosch
1997-07-03  0:00       ` Robert Dewar
1997-07-04  0:00         ` Geert Bosch
1997-07-04  0:00           ` Robert Dewar
1997-07-04  0:00         ` Geert Bosch
1997-06-28  0:00 ` Robert I. Eachus
1997-06-28  0:00   ` Geert Bosch
1997-06-30  0:00     ` Robert I. Eachus
replies disabled

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