--- parser3/src/main/pa_string.C 2004/05/26 08:25:55 1.198 +++ parser3/src/main/pa_string.C 2004/09/13 10:39:17 1.200 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_STRING_C="$Date: 2004/05/26 08:25:55 $"; +static const char * const IDENT_STRING_C="$Date: 2004/09/13 10:39:17 $"; #include "pcre.h" @@ -21,13 +21,20 @@ int pa_atoi(const char* str, const Strin if(!str) return 0; - while(*str && isspace(*str)) + while(*str && isspace((unsigned char)*str)) str++; if(!*str) return 0; int result; char *error_pos; + bool negative=false; + if(str[0]=='-') { + negative=true; + str++; + } else if(str[0]=='+') { + str++; + } // 0xABC if(str[0]=='0') if(str[1]=='x' || str[1]=='X') @@ -39,9 +46,11 @@ int pa_atoi(const char* str, const Strin } else result=(int)strtol(str, &error_pos, 0); + if(negative) + result=-result; while(char c=*error_pos++) - if(!isspace(c)) + if(!isspace((unsigned char)c)) throw Exception("number.format", problem_source, problem_source?"invalid number (int)": "'%s' is invalid number (int)", str); @@ -53,24 +62,36 @@ double pa_atod(const char* str, const St if(!str) return 0; - while(*str && isspace(*str)) + while(*str && isspace((unsigned char)*str)) str++; if(!*str) return 0; double result; char *error_pos; + bool negative=false; + if(str[0]=='-') { + negative=true; + str++; + } else if(str[0]=='+') { + str++; + } // 0xABC if(str[0]=='0') if(str[1]=='x' || str[1]=='X') result=(double)(unsigned long)strtol(str, &error_pos, 0); - else - result=(double)strtod(str+1/*skip leading 0*/, &error_pos); + else { + // skip leading 0000, to disable octal interpretation + do str++; while(*str=='0'); + result=(double)strtod(str, &error_pos); + } else result=(double)strtod(str, &error_pos); + if(negative) + result=-result; while(char c=*error_pos++) - if(!isspace(c)) + if(!isspace((unsigned char)c)) throw Exception("number.format", problem_source, problem_source?"invalid number (double)": "'%s' is invalid number (double)", str);