--- parser3/src/main/pa_string.C 2001/02/13 10:50:23 1.22 +++ parser3/src/main/pa_string.C 2001/02/21 12:44:02 1.27 @@ -1,5 +1,5 @@ /* - $Id: pa_string.C,v 1.22 2001/02/13 10:50:23 paf Exp $ + $Id: pa_string.C,v 1.27 2001/02/21 12:44:02 paf Exp $ */ #include @@ -23,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; @@ -32,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(); @@ -57,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]; @@ -88,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; @@ -111,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; @@ -208,6 +214,54 @@ bool String::operator == (const String& return a_break==b_break; } +bool String::operator == (char* b_ptr) const { + size_t b_size=b_ptr?strlen(b_ptr):0; + if(size() != b_size) + return false; + + const Chunk *a_chunk=&head; + const Chunk::Row *a_row=a_chunk->rows; + int a_offset=0; + int b_offset=0; + Chunk::Row *a_end=append_here; + int a_countdown=a_chunk->count; + bool a_break=false; + bool b_break=false; + while(true) { + int size_diff= + (a_row->item.size-a_offset)- + (b_size-b_offset); + + if(size_diff==0) { // a has same size as b + if(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) + return false; + a_row++; a_countdown--; a_offset=0; + b_break=true; + } else if (size_diff>0) { // a longer + if(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, b_size-b_offset)!=0) + return false; + a_offset+=b_size-b_offset; + b_break=true; + } else { // b longer + if(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) + return false; + b_offset+=a_row->item.size-a_offset; + a_row++; a_countdown--; a_offset=0; + } + + a_break=a_row==a_end; + if(a_break || b_break) + break; + + if(!a_countdown) { + a_chunk=a_row->link; + a_row=a_chunk->rows; + a_countdown=a_chunk->count; + } + } + return a_break==b_break; +} +/* String& String::append(const String_iterator& begin, const String_iterator& end) { //TODO return *this; @@ -219,6 +273,10 @@ 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+1); +} + // String_iterator String_iterator::String_iterator(String& astring) : string(astring) { @@ -226,6 +284,10 @@ String_iterator::String_iterator(String& 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()() const { return position?*position:0; @@ -247,7 +309,7 @@ void String_iterator::skip() { if(read_here==link_row) { String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise(0, 0, + string.pool().exception().raise(0, 0, &string, "String_iterator::skip() missed " "read_here==string.append_here check"); @@ -278,7 +340,7 @@ bool String_iterator::skip_to(char c) { if(read_here==link_row) { String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise(0, 0, + string.pool().exception().raise(0, 0, &string, "String_iterator::skip_to(char) missed " "read_here==string.append_here check"); @@ -308,7 +370,7 @@ int String_iterator::skip_to(Char_types& if(read_here==link_row) { String::Chunk *chunk=link_row->link; if(!chunk) - string.pool.exception().raise(0, 0, + string.pool().exception().raise(0, 0, &string, "String_iterator::skip_to(Char_type) missed " "read_here==string.append_here check"); @@ -319,3 +381,4 @@ int String_iterator::skip_to(Char_types& position=read_here->item.ptr; } } +*/ \ No newline at end of file