--- parser3/src/main/pa_string.C 2001/01/29 22:34:58 1.16 +++ parser3/src/main/pa_string.C 2001/02/13 10:09:53 1.20 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.16 2001/01/29 22:34:58 paf Exp $ + $Id: pa_string.C,v 1.20 2001/02/13 10:09:53 paf Exp $ */ #include @@ -8,12 +8,10 @@ #include "pa_string.h" #include "pa_hash.h" -void *String::operator new(size_t size, Pool& apool) { - return apool.malloc(size); -} +// String String::String(Pool& apool) : - pool(apool) { + Pooled(apool) { head.count=curr_chunk_rows=CR_PREALLOCATED_COUNT; append_here=head.rows; head.preallocated_link=0; @@ -33,7 +31,7 @@ void String::expand() { } String::String(const String& src) : - pool(src.pool) { + Pooled(src.pool) { head.count=CR_PREALLOCATED_COUNT; int src_used_rows=src.used_rows(); @@ -208,3 +206,95 @@ bool String::operator == (const String& } return a_break==b_break; } + +String& String::append(const String_iterator& begin, const String_iterator& end) { + return z; +} + +// Char_set + +Char_set::Char_set() { + memset(bools, 0, sizeof(bools)); +} + +// String_iterator + + // home string + String& string; + // the row in which we are + Chunk::Row *read_here; + // position in that row's string fragment + int offset; + // when read_here reaches this row, move to the next chunk + Chunk::Row *link_row; + + bool feof; + +String_iterator::String_iterator(String& astring) : + string(astring), + offset(0), + feof(astring.size()==0), + read_here(astring.head.rows), + link_row(astring.preallocated_link) { +} + +char String_iterator::operator() { + return feof?0:read_here->item.ptr[offset]; +} + +void String_iterator::skip() { + if(feof) + return; + + if(++offset==read_here->item.size) { + if(++read_here==string.append_here) { + feof=true; + return; + } + offset=0; + if(read_here==link_row) { + Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise( + "String_iterator::skip() missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=chunk->rows[chunk->count]; + } + } +} + +bool String_iterator::skip_to(char c) { + while(!feof) { + void *pos=memchr(read_here->ptr+offset, c, read_here->size-offset); + if(pos) { + offset=pos-read_here->ptr; + return true; + } + + if(++read_here==string.append_here) { + feof=true; + return false; + } + offset=0; + if(read_here==link_row) { + Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise( + "String_iterator::skip_to(char) missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=chunk->rows[chunk->count]; + } + } + return false; +} + +int String_iterator::skip_to(Char_type& types) { + for(; !feof; skip()) + if(char type=types.get(operator())) + return type; + return 0; +}