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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.68.132.234 with SMTP id ox10mr1901730pbb.8.1413999868729; Wed, 22 Oct 2014 10:44:28 -0700 (PDT) X-Received: by 10.50.141.138 with SMTP id ro10mr434388igb.16.1413999868628; Wed, 22 Oct 2014 10:44:28 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!uq10no15716226igb.0!news-out.google.com!ks2ni543igb.0!nntp.google.com!h18no8836486igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 22 Oct 2014 10:44:27 -0700 (PDT) In-Reply-To: <7c1b89e6-9ab8-4faa-b60c-c5c4683f0bff@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <7c1b89e6-9ab8-4faa-b60c-c5c4683f0bff@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1c18d4c3-aa53-4547-85c9-55477cde7364@googlegroups.com> Subject: Re: Assembling Complex Strings Containing Carriage Returns Prior to Using Ada.Text_IO.Put? From: Adam Beneschan Injection-Date: Wed, 22 Oct 2014 17:44:28 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.giganews.com comp.lang.ada:189978 Date: 2014-10-22T10:44:27-07:00 List-Id: On Tuesday, October 21, 2014 10:57:39 PM UTC-7, NiGHTS wrote: > I am converting some code from C to Ada which involves building a complex= string containing '\n' characters which would eventually be displayed on t= he standard output console using the printf() function.=20 > I tried to copy the same strategy of building the string in Ada like this= : > Complex_String : Ada.Strings.Unbounded.Unbounded_String; >=20 > EOL : String :=3D ASCII.CR'Img; As others have pointed out, 'Img is a GNAT-defined attribute; it depends on= the Ada-defined attribute 'Image. 'Image is not intended to convert a Cha= racter to a one-character String. If you say C : Character :=3D 'x'; S : String :=3D Character'Image (C); S will have length 3 and will be "'x'". Character is an enumeration type in Ada, although it's somewhat special. B= ut the rules for 'Image (and its converse, 'Value) are the same as for othe= r enumeration types: they give you (or expect) a string that looks like wha= t the enumeration value would look like in the enumeration declaration. Fo= r example, with this enumeration type: type Color is (RED, GREEN, BLUE); the 'Image attribute will produce "RED", "GREEN", or "BLUE". (It's always = upper-case for identifiers.) And for an enumeration type that has characte= r literals mixed in: type Whatsit is (This, That, '?'); 'Image will produce "THIS", "THAT", or "'?'". (What makes Character specia= l is that if you give it a non-printable character, there are special rules= for what 'Image returns; in your case it returned "CR".) -- Adam