--- parser3/src/main/pa_string.C 2001/10/29 16:56:31 1.117 +++ parser3/src/main/pa_string.C 2001/11/16 13:58:28 1.121 @@ -2,9 +2,9 @@ Parser: string class. @see untasize_t.C. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_string.C,v 1.117 2001/10/29 16:56:31 paf Exp $ + $Id: pa_string.C,v 1.121 2001/11/16 13:58:28 paf Exp $ */ #include "pa_config_includes.h" @@ -23,14 +23,12 @@ #include "pa_dictionary.h" String::String(Pool& apool, const char *src, size_t src_size, bool tainted) : - Pooled(apool), - forigins_mode(false) { + Pooled(apool) { last_chunk=&head; head.count=CR_PREALLOCATED_COUNT; append_here=head.rows; head.preallocated_link=0; link_row=&head.rows[head.count]; - fsize=0; if(src) if(tainted) @@ -40,8 +38,7 @@ String::String(Pool& apool, const char * } String::String(const String& src) : - Pooled(src.pool()), - forigins_mode(false) { + Pooled(src.pool()) { head.count=CR_PREALLOCATED_COUNT; uint src_used_rows=src.used_rows(); @@ -96,7 +93,24 @@ String::String(const String& src) : } link_row->link=0; src_used_rows; - fsize=src.fsize; +} + +size_t String::size() const { + size_t result=0; + const Chunk *chunk=&head; + do { + const Chunk::Row *row=chunk->rows; + for(uint i=0; icount; i++, row++) { + if(row==append_here) + goto break2; + + result+=row->item.size; + } + chunk=row->link; + } while(chunk); + +break2: + return result; } /// @todo not very optimal @@ -158,7 +172,7 @@ String& String::real_append(STRING_APPEN expand(); append_here->item.ptr=src; - fsize+=append_here->item.size=size; + append_here->item.size=size; append_here->item.lang=lang; #ifndef NO_STRING_ORIGIN append_here->item.origin.file=file; @@ -170,7 +184,7 @@ String& String::real_append(STRING_APPEN } char String::first_char() const { - if(!fsize) + if(!used_rows()) throw Exception(0, 0, this, "getting first char of empty string"); @@ -358,7 +372,7 @@ int String::cmp(int& partial, const char #ifndef NO_STRING_ORIGIN const Origin& String::origin() const { - if(!fsize) { + if(!used_rows()) { static const Origin empty_origin={"empty string"}; return empty_origin; } @@ -529,7 +543,7 @@ bool String::match(const unsigned char * throw Exception(0, 0, aorigin, "regexp is empty"); - const char *pattern=regexp.cstr(UL_AS_IS); + const char *pattern=regexp.cstr(); const char *errptr; int erroffset; int option_bits[2]; regex_options(options?options->cstr():0, option_bits); @@ -554,7 +568,7 @@ bool String::match(const unsigned char * } int startoffset=0; - const char *subject=cstr(UL_AS_IS); + const char *subject=cstr(); int length=strlen(subject); int ovecsize; int *ovector=(int *)malloc(sizeof(int)*