--- parser3/src/main/pa_string.C 2002/09/17 14:22:29 1.170 +++ parser3/src/main/pa_string.C 2003/01/22 15:39:08 1.172.2.1 @@ -1,17 +1,17 @@ /** @file Parser: string class. @see untasize_t.C. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_STRING_C="$Date: 2002/09/17 14:22:29 $"; +static const char* IDENT_STRING_C="$Date: 2003/01/22 15:39:08 $"; #include "pcre.h" #include "pa_pool.h" #include "pa_string.h" -#include "pa_hash.h" +//#include "pa_hash.h" #include "pa_exception.h" #include "pa_common.h" #include "pa_array.h" @@ -26,7 +26,7 @@ static const char* IDENT_STRING_C="$Date #ifdef DEBUG_STRING_APPENDS_VS_EXPANDS ulong string_piece_appends=0; #endif - +/* String& String::OnPool(Pool& apool, const char *local_src, size_t src_size, bool tainted) { if(local_src && *local_src) { if(src_size==0) @@ -38,8 +38,8 @@ String& String::OnPool(Pool& apool, cons } else return *new(apool) String(apool); } -String::String(Pool& apool, const char *src, size_t src_size, bool tainted) : - Pooled(apool) { +*/ +String::String(const char *src, size_t src_size, bool tainted) { last_chunk=&head.chunk; head.chunk.count=CR_PREALLOCATED_COUNT; append_here=head.chunk.rows; @@ -51,14 +51,17 @@ String::String(Pool& apool, const char * APPEND_CLEAN(src, src_size, 0, 0); } -String::String(const String& src) : - Pooled(src.pool()) { +String::String(const String& src) { last_chunk=&head.chunk; head.chunk.count=CR_PREALLOCATED_COUNT; append_here=head.chunk.rows; append(src, UL_PASS_APPENDED); } +void String::~String() { + // @todonow +} + size_t String::size() const { size_t result=0; @@ -81,12 +84,12 @@ void String::expand() { if(new_chunk_count>max_integral(Chunk::count_type)) new_chunk_count=max_integral(Chunk::count_type); - Chunk *new_chunk=static_cast(malloc( + Chunk *new_chunk=static_cast(pa_malloc( sizeof(Chunk)// count+interpadding(?)+rows[CR_PREALLOCATED_COUNT]+tailpadding(??) -sizeof(Chunk::rows_type) // PREALLOCATED rows +sizeof(Chunk::Row)*new_chunk_count // neaded rows +sizeof(Chunk *) // link size - , 10)); + )); new_chunk->rows[new_chunk->count=new_chunk_count].link=0; last_chunk->rows[last_chunk->count].link=new_chunk; @@ -332,7 +335,7 @@ const Origin& String::origin() const { #endif String& String::mid(size_t start, size_t finish) const { - String& result=*NEW String(pool()); + String& result=*new String(); start=min(start, size()); finish=max(start, finish); @@ -459,7 +462,7 @@ static void regex_options(const String * {"'", 0, 0, 0, 0, &need_pre_post_match}, {0} }; - result[0]=PCRE_EXTRA | PCRE_DOTALL; + result[0]=PCRE_EXTRA | PCRE_DOTALL | PCRE_DOLLAR_ENDONLY; result[1]=0; if(options) @@ -476,7 +479,7 @@ static void regex_options(const String * } /// @todo make replacement Table stacked -bool String::match( +bool String::match(Charset& source_charset, const String *aorigin, const String& regexp, const String *options, @@ -498,7 +501,7 @@ bool String::match( *was_global=option_bits[1]!=0; pcre *code=pcre_compile(pattern, option_bits[0], &errptr, &erroffset, - pool().get_source_charset().pcre_tables); + source_charset.pcre_tables); if(!code) throw Exception(0, @@ -520,7 +523,7 @@ bool String::match( int ovector[ovecsize]; // create table - *table=NEW Table(pool(), *string_match_table_template); + *table=new Table(*string_match_table_template); int exec_option_bits=0; int prestart=0; @@ -547,7 +550,7 @@ bool String::match( int prefinish=ovector[0]; poststart=ovector[1]; - Array& row=*NEW Array(pool()); + Array& row=*new Array(); row+=need_pre_post_match?&mid(0, prefinish):0; // .prematch column value row+=need_pre_post_match?&mid(prefinish, poststart):0; // .match row+=need_pre_post_match?&mid(poststart, postfinish):0; // .postmatch @@ -573,10 +576,9 @@ bool String::match( } } -String& String::change_case(Pool& pool, - Change_case_kind kind) const { - const unsigned char *tables=pool.get_source_charset().pcre_tables; - String& result=*new(pool) String(pool); +String& String::change_case(Charset& source_charset, Change_case_kind kind) const { + const unsigned char *tables=source_charset.pcre_tables; + String& result=*new String(); const unsigned char *a; const unsigned char *b; @@ -599,7 +601,7 @@ String& String::change_case(Pool& pool, } STRING_FOREACH_ROW( - char *new_cstr=(char *)pool.malloc(row->item.size, 12); + char *new_cstr=(char *)pa_malloc(row->item.size); char *dest=new_cstr; const char *src=row->item.ptr; for(int size=row->item.size; size--; src++) { @@ -619,11 +621,11 @@ String& String::change_case(Pool& pool, } /// @test if in some piece were found no dict words, append it, not it's duplicate -String& String::replace(Pool& pool, Dictionary& dict) const { +String& String::replace(Dictionary& dict) const { char *lcstr=cstr(); const char *current=lcstr; - String& result=*new(pool) String(pool); + String& result=*new String(); STRING_FOREACH_ROW( IFNDEF_NO_STRING_ORIGIN( const char *joined_origin_file=row->item.origin.file; @@ -645,7 +647,7 @@ IFNDEF_NO_STRING_ORIGIN( // & one step back, see STRING_FOREACH_ROW --row; ++countdown; - char *new_cstr=(char *)pool.malloc((size_t)ceil(joined_size*dict.max_ratio()), 14); + char *new_cstr=(char *)pa_malloc((size_t)ceil(joined_size*dict.max_ratio())); char *dest=new_cstr; while(joined_size) { // there is a row where first column starts 'joined_ptr' @@ -670,11 +672,11 @@ IFNDEF_NO_STRING_ORIGIN( return result; } -String& String::join_chains(Pool& pool, char** acstr) const { +String& String::join_chains(char** acstr) const { char *lcstr=cstr(); const char *current=lcstr; - String& result=*new(pool) String(pool); + String& result=*new String(); STRING_FOREACH_ROW( IFNDEF_NO_STRING_ORIGIN( const char *joined_origin_file=row->item.origin.file; @@ -791,7 +793,7 @@ void String::serialize(size_t prolog_siz prolog_size +used_rows()*(sizeof(uchar)+sizeof(ushort)) +size(); - buf=malloc(buf_size,15); + buf=pa_malloc(buf_size); char *cur=(char *)buf+prolog_size; STRING_FOREACH_ROW(