--- parser3/src/main/pa_string.C 2001/03/29 16:12:46 1.55 +++ parser3/src/main/pa_string.C 2001/04/02 15:59:56 1.59 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.C,v 1.55 2001/03/29 16:12:46 paf Exp $ + $Id: pa_string.C,v 1.59 2001/04/02 15:59:56 paf Exp $ */ #include "pa_config_includes.h" @@ -225,6 +225,7 @@ break2: } int String::cmp(int& partial, const String& src, size_t this_offset) const { + partial=-1; this_offset=min(this_offset, size()-1); const Chunk *a_chunk=&head; @@ -295,42 +296,51 @@ int String::cmp(int& partial, const Stri } } -int String::cmp(int& partial, const char* b_ptr, size_t src_size) const { +int String::cmp(int& partial, const char* b_ptr, size_t src_size, + size_t this_offset) const { + partial=-1; size_t b_size=src_size?src_size:b_ptr?strlen(b_ptr):0; + this_offset=min(this_offset, size()-1); - partial=-1; const Chunk *a_chunk=&head; const Chunk::Row *a_row=a_chunk->rows; - size_t a_offset=0; + size_t a_offset=this_offset; size_t b_offset=0; Chunk::Row *a_end=append_here; size_t a_countdown=a_chunk->count; bool a_break=false; bool b_break=false; - while(true) { + for(size_t pos=0; true; pos+=a_row->item.size) { a_break=a_row==a_end; if(a_break || b_break) break; - int size_diff= - (a_row->item.size-a_offset)- - (b_size-b_offset); - - if(size_diff==0) { // a has same size as b - if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) - return result; - a_row++; a_countdown--; a_offset=0; - b_break=true; - } else if (size_diff>0) { // a longer - if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, b_size-b_offset)!=0) - return result; - a_offset+=b_size-b_offset; - b_break=true; - } else { // b longer - if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) - return result; - b_offset+=a_row->item.size-a_offset; - a_row++; a_countdown--; a_offset=0; + if(pos+a_row->item.size > this_offset) { + int size_diff= + (a_row->item.size-a_offset)- + (b_size-b_offset); + + if(size_diff==0) { // a has same size as b + if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, + a_row->item.size-a_offset)!=0) + return result; + a_row++; a_countdown--; a_offset=0; + b_break=true; + } else if (size_diff>0) { // a longer + if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, + b_size-b_offset)!=0) + return result; + a_offset+=b_size-b_offset; + b_break=true; + } else { // b longer + if(size_t result=memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, + a_row->item.size-a_offset)!=0) + return result; + b_offset+=a_row->item.size-a_offset; + a_row++; a_countdown--; a_offset=0; + } + } else { + a_row++; a_countdown--; a_offset-=a_row->item.size; } if(!a_countdown) { @@ -396,12 +406,24 @@ break2: return result; } -size_t String::pos(const String& substr) const { - for(size_t result=0; result