--- parser3/src/main/pa_string.C 2004/02/27 15:24:03 1.196 +++ 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/02/27 15:24:03 $"; +static const char * const IDENT_STRING_C="$Date: 2004/09/13 10:39:17 $"; #include "pcre.h" @@ -21,24 +21,36 @@ 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') result=(int)(unsigned long)strtol(str, &error_pos, 0); - else - result=(int)strtol(str+1/*skip leading 0*/, &error_pos, 0); + else { + // skip leading 0000, to disable octal interpretation + do str++; while(*str=='0'); + result=(int)strtol(str, &error_pos, 0); + } 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); @@ -50,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); @@ -149,7 +173,6 @@ String::Body String::Body::trim(String:: return *this; if(!chars) chars=" \t\n"; // white space - Body result=*this; size_t start=0; size_t end=our_length; @@ -670,7 +693,7 @@ const char* String::Languages::v() const return (const char*)&langs; } const char* String::v() const { - const int LIMIT_VIEW=20; + const uint LIMIT_VIEW=20; char* buf=(char*)malloc(MAX_STRING); const char*body_view=body.v(); const char*langs_view=langs.v(); @@ -706,4 +729,4 @@ const String& String::trim(String::Trim_ ASSERT_STRING_INVARIANT(result); return result; -} \ No newline at end of file +}