Re: pseudo-specs for a String class: char &

From: Kinkie <gkinkie_at_gmail.com>
Date: Tue, 2 Sep 2008 12:20:26 +0200

On Tue, Sep 2, 2008 at 6:38 AM, Alex Rousskov
<rousskov_at_measurement-factory.com> wrote:
> On Tue, 2008-09-02 at 15:37 +1200, Amos Jeffries wrote:
>
>> There are two versions of this needed;
>>
>> One: const char ...() const; for read-only access to a char. With tests
>> returning NULL char or other safe abortion for out-of-range requests.
>>
>> The other: char ...(); for write-access, with full tests for string
>> expansion if necessary to store the new data.
>
> you probably meant "char &()" for the second one, but please be extra
> careful there: There are C++ gurus that consider write character access
> in a string via a char reference nearly impossible to implement safely.

It could probably be done, but honestly I'm not planning to implement that.

> My recommendation is to drop character access, especially the writeable
> character access via a reference from any buffer- or string-related
> class.

Write: agreed.
Read: might be useful for the HTTP parser.
Stuff like:

KBuf reqhdr = (whatever gets in from comm)
Kbuf hdrline=reqhdr->nextToken("\n");
if (hdrline[hdrline.len()-1]=='\r')
    hrline.truncate(hdrline.len()-1); //chop \r off

Syntax for the last two lines might be a little handier, such as:

if (hdrline.charAt(1,FROM_END)=='\r')
   hdrline.chop(1);

-- 
 /kinkie
Received on Tue Sep 02 2008 - 10:20:29 MDT

This archive was generated by hypermail 2.2.0 : Wed Sep 03 2008 - 12:00:03 MDT