--- parser3/src/main/pa_string.C 2001/01/29 22:34:58 1.16 +++ parser3/src/main/pa_string.C 2001/02/14 13:40:55 1.23 @@ -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.23 2001/02/14 13:40:55 paf Exp $ */ #include @@ -7,13 +7,12 @@ #include "pa_pool.h" #include "pa_string.h" #include "pa_hash.h" +#include "pa_exception.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 +32,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(); @@ -89,6 +88,11 @@ String::String(const String& src) : fused_rows=src_used_rows; fsize=src.fsize; } +/* +String(const String_iterator& begin, const String_iterator& end) { + ;//TODO +} +*/ String& String::real_append(STRING_APPEND_PARAMS) { if(!src) @@ -208,3 +212,119 @@ bool String::operator == (const String& } return a_break==b_break; } + +String& String::append(const String_iterator& begin, const String_iterator& end) { + //TODO + return *this; +} + +// Char_types + +Char_types::Char_types() { + memset(types, 0, sizeof(types)); +} + +void Char_types::set(char from, char to, int type) { + memset(&types[static_cast(from)], type, to-from); +} + +// String_iterator + +String_iterator::String_iterator(String& astring) : string(astring) { + read_here=string.head.rows; + position=string.size()==0?0:read_here->item.ptr; + link_row=reinterpret_cast(string.head.preallocated_link); +} + +char String_iterator::operator()() const { + return position?*position:0; +} + +void String_iterator::skip() { + if(!position) + return; + + if(++position== + read_here->item.ptr+ + read_here->item.size) { + + // next row + if(++read_here==string.append_here) { + position=0; + return; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise(0, 0, + &string, + "String_iterator::skip() missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=&chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +} + +bool String_iterator::skip_to(char c) { + if(!position) + return false; + + while(true) { + if(char *found=static_cast( + memchr(position, c, read_here->item.size-(position-read_here->item.ptr)))) { + position=found; + return true; + } + + // next row + if(++read_here==string.append_here) { + position=0; + return false; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise(0, 0, + &string, + "String_iterator::skip_to(char) missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=&chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +} + +int String_iterator::skip_to(Char_types& types) { + if(!position) + return false; + + while(true) { + int countdown=read_here->item.size-(position-read_here->item.ptr); + for(; countdown--; position++) + if(int type=types.get(*position)) + return type; + + // next row + if(++read_here==string.append_here) { + position=0; + return -1; + } + if(read_here==link_row) { + String::Chunk *chunk=link_row->link; + if(!chunk) + string.pool.exception().raise(0, 0, + &string, + "String_iterator::skip_to(Char_type) missed " + "read_here==string.append_here check"); + + read_here=chunk->rows; + link_row=&chunk->rows[chunk->count]; + } + position=read_here->item.ptr; + } +}