--- parser3/src/main/pa_string.C 2001/02/13 10:30:22 1.21 +++ parser3/src/main/pa_string.C 2001/02/20 18:45:53 1.26 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.21 2001/02/13 10:30:22 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,9 +213,10 @@ 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_types @@ -217,26 +225,23 @@ Char_types::Char_types() { memset(types, 0, sizeof(types)); } -// 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; +void Char_types::set(char from, char to, int type) { + memset(&types[static_cast(from)], type, to-from+1); +} - bool feof; +// 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=string.preallocated_link; + link_row=reinterpret_cast(string.head.preallocated_link); +} +/* +String_iterator::String_iterator(String_iterator& asi) { + //TODO } -char String_iterator::operator() { +char String_iterator::operator()() const { return position?*position:0; } @@ -250,18 +255,19 @@ void String_iterator::skip() { // next row if(++read_here==string.append_here) { - feof=true; + position=0; return; } 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; } @@ -273,7 +279,7 @@ bool String_iterator::skip_to(char c) { while(true) { if(char *found=static_cast( - memchr(ptr, c, read_here->size-(position-read_here->ptr)))) { + memchr(position, c, read_here->item.size-(position-read_here->item.ptr)))) { position=found; return true; } @@ -284,25 +290,26 @@ bool String_iterator::skip_to(char c) { return false; } 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; } } -int String_iterator::skip_to(Char_type& types) { +int String_iterator::skip_to(Char_types& types) { if(!position) return false; while(true) { - int countdown=read_here->size-(position-read_here->ptr))); + int countdown=read_here->item.size-(position-read_here->item.ptr); for(; countdown--; position++) if(int type=types.get(*position)) return type; @@ -310,18 +317,20 @@ int String_iterator::skip_to(Char_type& // next row if(++read_here==string.append_here) { position=0; - return 0; + return -1; } 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_type) 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; } } +*/ \ No newline at end of file