Re: pseudo-specs for a String class

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Mon, 1 Sep 2008 13:21:33 +1200 (NZST)

> On Sun, Aug 31, 2008 at 6:00 PM, Adrian Chadd <adrian_at_squid-cache.org>
> wrote:
>> Do you really want to provide a 'consume' interface for a low-level
>> representation of memory?
>>
>> I think trying to replace MemBuf with this new buffer is a bit silly.
>> Sure, use it -in- MemBuf, along with all the other places that buffers
>> are used.
>>
>> What about strtok()? Why would you want to tokenise data?
>
> I'd like it to be used
> - everywhere MemBuf is used
> - everywhere a char* is used for a string
> - strtok, strchr, strstr, etc to be used in the HTTP parser
>
> All of the above with increased efficiency both in terms callers' LOC
> and performance.
>
>
> Given:
> KBuf src="GET http://some.url/ HTTP/1.0\r\nHost: some.url\r\n\r\n"
> KBuf out;
>
> The following are expected to be equivalent:
> ====
> u_int32_t pos=src.index('\n');
> out=src.substr(0,pos);
> src=src.substr(pos,-1); //to end-of-string
> ====
> out=src.consume(src.index('\n'));
> ====
> out=src.nextToken('\n');
> ====
>

Nice, that should help the parser re-work quite a bit. Though make sure
the nextToken only applies to the src KBuf object. Our biggest existing
problems with strtok() is its internal 'static global' design.

Amos
Received on Mon Sep 01 2008 - 01:21:35 MDT

This archive was generated by hypermail 2.2.0 : Mon Sep 01 2008 - 12:00:06 MDT