--- parser3/src/main/pa_string.C 2001/05/17 10:12:28 1.87 +++ parser3/src/main/pa_string.C 2001/05/21 16:38:46 1.89 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: pa_string.C,v 1.87 2001/05/17 10:12:28 parser Exp $ + $Id: pa_string.C,v 1.89 2001/05/21 16:38:46 parser Exp $ */ #include "pa_config_includes.h" @@ -485,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, @@ -635,3 +636,38 @@ break2: return result; } + +double String::as_double() { + 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() { + 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; +}