--- parser3/src/main/pa_string.C 2001/03/10 12:12:51 1.35 +++ parser3/src/main/pa_string.C 2001/03/18 13:38:48 1.41 @@ -1,5 +1,9 @@ /* - $Id: pa_string.C,v 1.35 2001/03/10 12:12:51 paf Exp $ + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: pa_string.C,v 1.41 2001/03/18 13:38:48 paf Exp $ */ #include @@ -11,7 +15,7 @@ // String -String::String(Pool& apool) : +String::String(Pool& apool, const char *src, bool tainted) : Pooled(apool) { last_chunk=&head; head.count=CR_PREALLOCATED_COUNT; @@ -19,6 +23,12 @@ String::String(Pool& apool) : head.preallocated_link=0; link_row=&head.rows[head.count]; fused_rows=fsize=0; + + if(src) + if(tainted) + APPEND_TAINTED(src, 0, 0, 0); + else + APPEND(src, 0, 0, 0); } void String::expand() { @@ -32,8 +42,7 @@ void String::expand() { link_row->link=0; } -String::String(const String& src) : - Pooled(src.pool()) { +String::String(const String& src) : Pooled(src.pool()) { head.count=CR_PREALLOCATED_COUNT; int src_used_rows=src.used_rows(); @@ -143,7 +152,7 @@ String& String::append(const String& src return *this; } void String::set_lang(Chunk::Row *row, Untaint_lang lang, size_t size) { - if(lang==PASS_APPENDED) + if(lang==PASS_APPEND) return; while(size--) { @@ -153,6 +162,23 @@ void String::set_lang(Chunk::Row *row, U } } +void String::change_lang(Untaint_lang lang) { + Chunk *chunk=&head; + do { + Chunk::Row *row=chunk->rows; + for(int i=0; icount; i++) { + if(row==append_here) + goto break2; + + row->item.lang=lang; + row++; + } + chunk=row->link; + } while(chunk); +break2: + return; +} + String& String::real_append(STRING_APPEND_PARAMS) { if(!src) return *this; @@ -166,7 +192,7 @@ String& String::real_append(STRING_APPEN append_here->item.ptr=src; fsize+=append_here->item.size=size; - append_here->item.lang=tainted?/*Untaint_lang::*/YES:Untaint_lang::NO; + append_here->item.lang=tainted?YES:NO; #ifndef NO_STRING_ORIGIN append_here->item.origin.file=file; append_here->item.origin.line=line; @@ -176,43 +202,6 @@ String& String::real_append(STRING_APPEN return *this; } -char *String::cstr() const { - char *result=static_cast(malloc(size()+1)); - - char *copy_here=result; - const Chunk *chunk=&head; - do { - const Chunk::Row *row=chunk->rows; - for(int i=0; icount; i++) { - if(row==append_here) - goto break2; - - switch(row->item.lang) { - case NO: - case YES: // for VString.get_double of tainted values - case AS_IS: - memcpy(copy_here, row->item.ptr, row->item.size); - break; - case HTML_TYPO: - memset(copy_here, '?', row->item.size); - break; - default: - THROW(0,0, - this, - "unknown untaint language #%d of %d piece", - static_cast(row->item.lang), - i); - } - copy_here+=row->item.size; - row++; - } - chunk=row->link; - } while(chunk); -break2: - *copy_here=0; - return result; -} - uint String::hash_code() const { uint result=0; @@ -296,7 +285,7 @@ int String::cmp(const String& src) const return result; } -bool String::operator == (char* b_ptr) const { +bool String::operator == (const char* b_ptr) const { size_t b_size=b_ptr?strlen(b_ptr):0; if(size() != b_size) return false;