--- parser3/src/main/pa_string.C 2002/04/22 14:25:41 1.158 +++ parser3/src/main/pa_string.C 2002/06/25 16:05:22 1.161 @@ -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.158 2002/04/22 14:25:41 paf Exp $ + $Id: pa_string.C,v 1.161 2002/06/25 16:05:22 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; @@ -694,6 +705,13 @@ double String::as_double() const { cstr=buf; } else cstr=this->cstr(); + while(*cstr && isspace(*cstr)) + cstr++; + if(!*cstr) + throw Exception("number.format", + this, + "blank string is invalid number (double)"); + char *error_pos; // 0xABC if(cstr[0]=='0') @@ -704,10 +722,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; } @@ -722,6 +741,13 @@ int String::as_int() const { cstr=buf; } else cstr=this->cstr(); + while(*cstr && isspace(*cstr)) + cstr++; + if(!*cstr) + throw Exception("number.format", + this, + "blank string is invalid number (int)"); + char *error_pos; // 0xABC if(cstr[0]=='0') @@ -732,10 +758,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; }