--- parser3/src/main/pa_string.C 2001/05/16 08:10:22 1.86 +++ parser3/src/main/pa_string.C 2001/05/21 16:39:32 1.90 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.C,v 1.86 2001/05/16 08:10:22 parser Exp $ + $Id: pa_string.C,v 1.90 2001/05/21 16:39:32 parser Exp $ */ #include "pa_config_includes.h" @@ -21,7 +21,6 @@ #include "pa_array.h" #include "pa_globals.h" #include "pa_table.h" -#include "pa_threads.h" String::String(Pool& apool, const char *src, size_t src_size, bool tainted) : Pooled(apool) { @@ -486,6 +485,7 @@ static void regex_options(char *options, } } +/// @todo maybe need speedup: some option to remove pre/match/post string generation bool String::match(const unsigned char *pcre_tables, const String *aorigin, const String& regexp, @@ -636,3 +636,38 @@ break2: return result; } + +double String::as_double() const { + double result; + const char *cstr=this->cstr(); + char *error_pos=0; + // 0xABC + if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) + result=(double)(unsigned long)strtol(cstr, &error_pos, 0); + else + result=strtod(cstr, &error_pos); + + if(error_pos && *error_pos) + THROW(0, 0, + this, + "invalid number (double)"); + + return result; +} +int String::as_int() const { + int result; + const char *cstr=this->cstr(); + char *error_pos=0; + // 0xABC + if(cstr[0]=='0' && (cstr[1]=='x' || cstr[1]=='X')) + result=(int)(unsigned long)strtol(cstr, &error_pos, 0); + else + result=(int)strtol(cstr, &error_pos, 0); + + if(error_pos && *error_pos) + THROW(0, 0, + this, + "invalid number (int)"); + + return result; +}