--- parser3/src/main/pa_string.C 2002/04/22 14:25:41 1.158 +++ parser3/src/main/pa_string.C 2002/08/01 11:26:51 1.164 @@ -3,10 +3,10 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: pa_string.C,v 1.158 2002/04/22 14:25:41 paf Exp $ */ +static const char* IDENT_STRING_C="$Id: pa_string.C,v 1.164 2002/08/01 11:26:51 paf Exp $"; + #include "pcre.h" #include "pa_pool.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; @@ -694,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') @@ -704,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; } @@ -716,12 +733,17 @@ int String::as_int() const { const char *cstr; char buf[MAX_NUMBER]; if(head.chunk.rows+1==append_here) { - int size=min(head.chunk.rows[0].item.size, MAX_NUMBER-1); + size_t size=min(head.chunk.rows[0].item.size, MAX_NUMBER-1); memcpy(buf, head.chunk.rows[0].item.ptr, size); buf[size]=0; cstr=buf; } else cstr=this->cstr(); + while(*cstr && isspace(*cstr)) + cstr++; + if(!*cstr) + return 0; + char *error_pos; // 0xABC if(cstr[0]=='0') @@ -732,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; }