--- parser3/src/main/pa_string.C 2001/02/13 10:09:53 1.20 +++ parser3/src/main/pa_string.C 2001/02/20 18:45:53 1.26 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.20 2001/02/13 10:09:53 paf Exp $ + $Id: pa_string.C,v 1.26 2001/02/20 18:45:53 paf Exp $ */ #include @@ -7,6 +7,7 @@ #include "pa_pool.h" #include "pa_string.h" #include "pa_hash.h" +#include "pa_exception.h" // String @@ -22,7 +23,7 @@ String::String(Pool& apool) : void String::expand() { curr_chunk_rows+=curr_chunk_rows*CR_GROW_PERCENT/100; Chunk *chunk=static_cast( - pool.malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); + pool().malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); chunk->count=curr_chunk_rows; link_row->link=chunk; append_here=chunk->rows; @@ -31,7 +32,7 @@ void String::expand() { } String::String(const String& src) : - Pooled(src.pool) { + Pooled(src.pool()) { head.count=CR_PREALLOCATED_COUNT; int src_used_rows=src.used_rows(); @@ -56,7 +57,7 @@ String::String(const String& src) : // remaining rows into new_chunk curr_chunk_rows=src_used_rows-head.count; Chunk *new_chunk=static_cast( - pool.malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); + pool().malloc(sizeof(int)+sizeof(Chunk::Row)*curr_chunk_rows+sizeof(Chunk *))); new_chunk->count=curr_chunk_rows; head.preallocated_link=new_chunk; append_here=link_row=&new_chunk->rows[curr_chunk_rows]; @@ -87,19 +88,25 @@ 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) return *this; - int len=strlen(src); - if(!len) + if(!size) + size=strlen(src); + if(!size) return *this; if(chunk_is_full()) expand(); append_here->item.ptr=src; - fsize+=append_here->item.size=len; + fsize+=append_here->item.size=size; #ifndef NO_STRING_ORIGIN append_here->item.origin.file=file; append_here->item.origin.line=line; @@ -110,7 +117,7 @@ String& String::real_append(STRING_APPEN } char *String::cstr() const { - char *result=static_cast(pool.malloc(size()+1)); + char *result=static_cast(pool().malloc(size()+1)); char *copy_here=result; const Chunk *chunk=&head; @@ -206,95 +213,124 @@ bool String::operator == (const String& } return a_break==b_break; } - +/* String& String::append(const String_iterator& begin, const String_iterator& end) { - return z; + //TODO + return *this; } -// Char_set +// Char_types + +Char_types::Char_types() { + memset(types, 0, sizeof(types)); +} -Char_set::Char_set() { - memset(bools, 0, sizeof(bools)); +void Char_types::set(char from, char to, int type) { + memset(&types[static_cast(from)], type, to-from+1); } // 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) { +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); +} +/* +String_iterator::String_iterator(String_iterator& asi) { + //TODO } -char String_iterator::operator() { - return feof?0:read_here->item.ptr[offset]; +char String_iterator::operator()() const { + return position?*position:0; } void String_iterator::skip() { - if(feof) + if(!position) return; - if(++offset==read_here->item.size) { + if(++position== + read_here->item.ptr+ + read_here->item.size) { + + // next row if(++read_here==string.append_here) { - feof=true; + position=0; return; } - offset=0; if(read_here==link_row) { - Chunk *chunk=link_row->link; + String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise( + 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]; + link_row=&chunk->rows[chunk->count]; } + position=read_here->item.ptr; } } 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; + 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) { - feof=true; + position=0; return false; } - offset=0; if(read_here==link_row) { - Chunk *chunk=link_row->link; + String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise( + 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]; + link_row=&chunk->rows[chunk->count]; } + position=read_here->item.ptr; } - return false; } -int String_iterator::skip_to(Char_type& types) { - for(; !feof; skip()) - if(char type=types.get(operator())) - return type; - return 0; +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; + } } +*/ \ No newline at end of file