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.1 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8bf89a9bbd99a65e X-Google-Attributes: gid103376,public From: Wes Groleau Subject: Re: array conversion - how to do? Date: 1997/06/27 Message-ID: <33B3DE95.41EF@does.not.exist.com>#1/1 X-Deja-AN: 253040086 Sender: usenet@most.fw.hac.com (News Administration) X-Nntp-Posting-Host: sparc02 References: <5opej8$rv5$1@gonzo.sun3.iaf.nl> Organization: See Warning Below! Newsgroups: comp.lang.ada Date: 1997-06-27T00:00:00+00:00 List-Id: 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! ----------------------------------------------------------------------