From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Out_File , excess line
Date: Wed, 27 Jan 2016 21:28:07 +0100
Date: 2016-01-27T21:28:07+01:00 [thread overview]
Message-ID: <n8b98s$7jm$1@gioia.aioe.org> (raw)
In-Reply-To: lylh7bweyp.fsf@pushface.org
On 2016-01-27 10:26, Simon Wright wrote:
> comicfanzine@gmail.com writes:
>
>> But , when we try to open the file manually , the text editor print :
>>
>> " This is not a text file . Type unknown ."
>> PACKAGE ST_IO RENAMES Ada.Streams.Stream_IO ;
>>
>> test_file : ST_IO.File_type ;
>>
>> Input_Stream : ST_IO.Stream_Access ;
> [...]
>> ST_IO.Create( File => test_file ,
>> Mode => ST_IO.Out_File ,
>> Name => "test" );
>>
>> Input_Stream := ST_IO.Stream( test_file );
>>
>> for j in 1..case_array'Length loop
>> Unbounded_String'Write( Input_Stream , case_array(j) );
>> end loop;
>
> 'Input_Stream' is a very odd name for a stream you're going to *output*
> to.
>
> What's happening is that (reasonably, though not as far as I can see
> discussed by the standard) GNAT treats Unbounded_String'Write as if an
> unbounded string is a discriminated type whose discriminants have
> defaults; that is, the discriminants (the array bounds) are output to
> the stream first, followed by the characters of the string. (This is
> what happens for String'Output; String'Write doesn't include the bounds;
> is the Unbounded_String'Write behaviour a bug or a feature?).
>
> So, if you Unbounded_String'Write "foo", you will get
> - 4 bytes containing binary 1, the first index of the content
> - 4 bytes containing binary 3, the last index of the content
> - 3 bytes of content, 'f' 'o' 'o'.
>
> Which looks nothing like a text file.
>
> You could try
>
> String'Write (Input_Stream, To_String (case_array (j)) & ASCII.LF);
This one of many reasons why no Unbounded_String should ever be used for
any text processing. That includes text buffers of course. Using
standard containers of Unbounded_String is probably least efficient
possible way to implement a text buffer.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2016-01-27 20:28 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-20 1:39 Out_File , excess line comicfanzine
2016-01-20 11:23 ` AdaMagica
2016-01-20 13:31 ` comicfanzine
2016-01-20 14:03 ` comicfanzine
2016-01-20 14:26 ` Dmitry A. Kazakov
2016-01-20 17:33 ` AdaMagica
2016-01-21 4:50 ` comicfanzine
2016-01-21 10:27 ` Jacob Sparre Andersen
2016-01-21 10:56 ` AdaMagica
2016-01-21 11:57 ` G.B.
2016-01-21 14:42 ` Dmitry A. Kazakov
2016-01-21 16:23 ` AdaMagica
2016-01-22 2:50 ` Dennis Lee Bieber
2016-01-21 13:38 ` Dennis Lee Bieber
2016-01-21 17:30 ` comicfanzine
2016-01-22 1:56 ` comicfanzine
2016-01-22 12:28 ` Brian Drummond
2016-01-22 20:01 ` comicfanzine
2016-01-23 20:06 ` comicfanzine
2016-01-27 9:26 ` Simon Wright
2016-01-27 19:32 ` Simon Wright
2016-01-27 21:31 ` Jeffrey R. Carter
2016-01-27 20:28 ` Dmitry A. Kazakov [this message]
2016-01-24 16:11 ` comicfanzine
2016-01-25 21:54 ` comicfanzine
2016-01-25 22:01 ` MM
2016-01-26 0:50 ` comicfanzine
2016-01-26 10:10 ` comicfanzine
2016-01-27 3:57 ` comicfanzine
2016-01-27 8:13 ` AdaMagica
2016-01-28 4:35 ` comicfanzine
2016-01-29 23:04 ` comicfanzine
2016-01-30 9:44 ` Simon Wright
2016-01-30 10:43 ` AdaMagica
2016-01-30 13:51 ` Simon Wright
2016-01-31 8:56 ` comicfanzine
2016-01-31 11:25 ` Simon Wright
2016-01-31 12:57 ` Dmitry A. Kazakov
2016-01-31 17:00 ` Simon Wright
2016-01-31 11:51 ` AdaMagica
2016-02-01 6:22 ` comicfanzine
2016-02-01 8:32 ` Dmitry A. Kazakov
2016-02-09 15:07 ` comicfanzine
2016-02-09 17:00 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox