--- parser3/src/main/pa_string.C 2001/03/21 14:06:46 1.47 +++ parser3/src/main/pa_string.C 2001/03/25 08:52:36 1.52 @@ -5,10 +5,10 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.C,v 1.47 2001/03/21 14:06:46 paf Exp $ + $Id: pa_string.C,v 1.52 2001/03/25 08:52:36 paf Exp $ */ -#include +#include "pa_config_includes.h" #include "pa_pool.h" #include "pa_string.h" @@ -194,7 +194,7 @@ String& String::real_append(STRING_APPEN append_here->item.ptr=src; fsize+=append_here->item.size=size; - append_here->item.lang=tainted?UL_YES:UL_NO; + append_here->item.lang=lang; #ifndef NO_STRING_ORIGIN append_here->item.origin.file=file; append_here->item.origin.line=line; @@ -287,11 +287,10 @@ int String::cmp(const String& src) const return result; } -bool String::operator == (const char* b_ptr) const { - size_t b_size=b_ptr?strlen(b_ptr):0; - if(size() != b_size) - return false; +int String::cmp(const char* b_ptr, int& partial, size_t src_size) const { + size_t b_size=src_size?src_size:b_ptr?strlen(b_ptr):0; + partial=-1; const Chunk *a_chunk=&head; const Chunk::Row *a_row=a_chunk->rows; int a_offset=0; @@ -301,47 +300,55 @@ bool String::operator == (const char* b_ bool a_break=false; bool b_break=false; while(true) { + 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(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) - return false; + if(int 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(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, b_size-b_offset)!=0) - return false; + if(int 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(memcmp(a_row->item.ptr+a_offset, b_ptr+b_offset, a_row->item.size-a_offset)!=0) - return false; + if(int 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; } - 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; + if(a_break==b_break) // ended simultaneously + return partial=0; + else if(a_break) // first bytes equal, but a ended before b + return partial=1; + else + return partial=2; } #ifndef NO_STRING_ORIGIN const Origin& String::origin() const { if(!fused_rows) THROW(0, 0, - 0, - "String::origin() of empty string called"); + 0, + "String::origin() of empty string called"); - return head.rows[0].item.origin; + // determining origin by last appended piece + // because first one frequently constant. + // ex: ^load[/file] "document_root" + "/file" + return append_here[-1].item.origin; } #endif