--- parser3/src/main/pa_string.C 2002/04/22 14:11:28 1.157 +++ parser3/src/main/pa_string.C 2002/06/26 10:35:16 1.162 @@ -4,7 +4,7 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - $Id: pa_string.C,v 1.157 2002/04/22 14:11:28 paf Exp $ + $Id: pa_string.C,v 1.162 2002/06/26 10:35:16 paf Exp $ */ #include "pcre.h" @@ -27,6 +27,17 @@ 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) + src_size=strlen(local_src); + + char *pooled_src=(char *)apool.malloc(src_size); + memcpy(pooled_src, local_src, src_size); + return *new(apool) String(apool, pooled_src, src_size, tainted); + } else + return *new(apool) String(apool); +} String::String(Pool& apool, const char *src, size_t src_size, bool tainted) : Pooled(apool) { last_chunk=&head.chunk; @@ -474,7 +485,7 @@ static void regex_options(const String * } /// @todo make replacement Table stacked -bool String::match(const char *acstr, +bool String::match( const String *aorigin, const String& regexp, const String *options, @@ -512,7 +523,7 @@ bool String::match(const char *acstr, info_substrings); } - const char *subject=acstr?acstr:cstr(); + const char *subject=cstr(); int length=strlen(subject); const int ovecsize=(1/*match*/+MAX_STRING_MATCH_TABLE_COLUMNS)*3; int ovector[ovecsize]; @@ -648,31 +659,6 @@ String& String::replace(Pool& pool, Dict return result; } -/// @test real! -bool String::is_join_chains_profitable() const { - // mimimum actually sizeof(String), - // but one must also consider CPU time optimize would eat - const int minimum_economy=sizeof(String)*2; - - size_t wasted=0; - STRING_FOREACH_ROW( - uchar joined_lang=row->item.lang; - STRING_PREPARED_FOREACH_ROW(*this, - if(row->item.lang==joined_lang) { - wasted+=sizeof(String::Chunk::rows_type); - if(wasted>minimum_economy) - return true; - } else - break; // before non-ours - ); - - // pointers are after joined piece - // & one step back, see STRING_FOREACH_ROW - --row; ++countdown; - ); - return false; -} - String& String::join_chains(Pool& pool, char** acstr) const { char *lcstr=cstr(); const char *current=lcstr; @@ -719,6 +705,11 @@ double String::as_double() const { cstr=buf; } else cstr=this->cstr(); + while(*cstr && isspace(*cstr)) + cstr++; + if(!*cstr) + return 0; + char *error_pos; // 0xABC if(cstr[0]=='0') @@ -729,10 +720,11 @@ double String::as_double() const { else result=(double)strtod(cstr, &error_pos); - if(*error_pos/*not EOS*/) - throw Exception("number.format", - this, - "invalid number (double)"); + while(char c=*error_pos++) + if(!isspace(c)) + throw Exception("number.format", + this, + "invalid number (double)"); return result; } @@ -747,6 +739,11 @@ int String::as_int() const { cstr=buf; } else cstr=this->cstr(); + while(*cstr && isspace(*cstr)) + cstr++; + if(!*cstr) + return 0; + char *error_pos; // 0xABC if(cstr[0]=='0') @@ -757,10 +754,11 @@ int String::as_int() const { else result=(int)strtol(cstr, &error_pos, 0); - if(*error_pos/*not EOS*/) - throw Exception("number.format", - this, - "invalid number (int)"); + while(char c=*error_pos++) + if(!isspace(c)) + throw Exception("number.format", + this, + "invalid number (int)"); return result; }