comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Reading the while standard input into a String
Date: Mon, 6 Jun 2011 14:05:27 +0200
Date: 2011-06-06T14:05:27+02:00	[thread overview]
Message-ID: <1ckesozpipi2y$.p1ei3zmgxjfc$.dlg@40tude.net> (raw)
In-Reply-To: slrniupbvs.i18.lithiumcat@sigil.instinctive.eu

On Mon, 6 Jun 2011 10:46:20 +0000 (UTC), Natasha Kerensikova wrote:

> Hello,
> 
> On 2011-06-06, Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>> On Sun, 5 Jun 2011 16:20:39 +0000 (UTC), Natasha Kerensikova wrote:
>>
>>> However I still read
>>> character by character
>>
>> You have to, because the definition of line end is language/OS/encoding
>> dependent, so in order to detect line ends properly you need to scan
>> characters one by one, maybe recoding them into the encoding used by the
>> parser (e.g. UTF-8). It does not make much sense to read input by arbitrary
>> size chunks. Read it line by line. If parser needs returns over the line
>> margin (unlikely), then keep read lines cached.
> 
> The line end detection problem is exactly why I wanted unprocessed input
> bytes.

There is no such thing as unprocessed input.

>>>  into a temporary buffer,
>>
>> Read it into the destination buffer.
> 
> Well the destination buffer for the processed text is a very inefficient
> place to store input text, because the processing involves a lot of
> insertions.

A temporary buffer makes it only slower.

> Moreover, because of the forward reference issue I detailed in another
> post, I cannot see how I can escape the schema:
> input stream --> temporary buffer --> output stream/buffer/storage

Input stream ---recoding---> Line buffer

(The line buffer could be bounded from above as Ludovic suggested.)

>> Don't use Unbounded_String; that is a
>> bad idea in almost all cases, this one included.
> 
> Would you explain why?

Because they are inefficient and do not have array view (lack indexing,
slicing, constraining).

> Unless there is a way to predict the left of the input, I need some
> text container able to grow as much as needed while reading.

String is such a container.

> But I guess you weren't calling using Unbounded_String a
> bad idea only because of performance, were you?

Yes, missing array view is the problem. In all cases you know the size in
advance or when the size incrementally grows use String allocated in the
heap. Unbounded_Strings can be used, for example, as members of
non-controlled records.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-06-06 12:05 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-05 16:20 Reading the while standard input into a String Natasha Kerensikova
2011-06-06  1:49 ` robin
2011-06-06  7:18 ` Dmitry A. Kazakov
2011-06-06 10:46   ` Natasha Kerensikova
2011-06-06 12:05     ` Dmitry A. Kazakov [this message]
2011-06-06 16:55       ` Jeffrey Carter
2011-06-06 17:42         ` Pascal Obry
2011-06-06 17:43         ` Pascal Obry
2011-06-06 18:31         ` Dmitry A. Kazakov
2011-06-06  8:09 ` stefan-lucks
2011-06-06  8:33 ` Ludovic Brenta
2011-06-06 10:08   ` Natasha Kerensikova
2011-06-06 10:27     ` Ludovic Brenta
2011-06-06 10:31       ` Ludovic Brenta
2011-06-06 12:07         ` Natasha Kerensikova
2011-06-06 15:18   ` Maciej Sobczak
2011-06-06 18:18     ` Dmitry A. Kazakov
2011-06-06 18:36       ` Maciej Sobczak
2011-06-06 18:53         ` Dmitry A. Kazakov
2011-06-06 19:10           ` J-P. Rosen
2011-06-06 19:46             ` Dmitry A. Kazakov
2011-06-06 23:37           ` Shark8
2011-06-07  3:00             ` Randy Brukardt
2011-06-07  7:25             ` Dmitry A. Kazakov
2011-06-07  7:32           ` Maciej Sobczak
2011-06-07  8:51             ` Dmitry A. Kazakov
2011-06-07  3:10         ` Randy Brukardt
2011-06-06 19:06       ` J-P. Rosen
2011-06-06 19:52         ` Dmitry A. Kazakov
2011-06-07  3:15         ` Randy Brukardt
2011-06-06 22:14   ` Robert A Duff
2011-06-06  9:46 ` Georg Bauhaus
2011-06-06 11:16 ` Georg Bauhaus
2011-06-06 12:11   ` Dmitry A. Kazakov
2011-06-06 13:32     ` Georg Bauhaus
2011-06-06 14:06       ` Dmitry A. Kazakov
2011-06-06 14:14         ` Georg Bauhaus
2011-06-07  3:19         ` Randy Brukardt
2011-06-06 18:14 ` John B. Matthews
2011-06-07 10:23   ` Martin
2011-06-07 16:57     ` John B. Matthews
2011-06-07 17:22     ` Robert A Duff
2011-06-07 17:55       ` John B. Matthews
2011-06-08  0:26         ` Robert A Duff
2011-06-08  7:38         ` Egil Høvik
2011-06-08  9:27           ` Martin
2011-06-08 12:04             ` Egil Høvik
2011-06-08 18:09               ` Niklas Holsti
2011-06-09  0:46                 ` Randy Brukardt
2011-06-10  8:22                   ` Martin
replies disabled

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