--- parser3/src/main/pa_string.C 2004/02/27 15:07:46 1.195 +++ parser3/src/main/pa_string.C 2004/07/28 13:43:58 1.199 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_STRING_C="$Date: 2004/02/27 15:07:46 $"; +static const char * const IDENT_STRING_C="$Date: 2004/07/28 13:43:58 $"; #include "pcre.h" @@ -21,7 +21,7 @@ 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; @@ -32,13 +32,16 @@ int pa_atoi(const char* str, const Strin 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); 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,7 +53,7 @@ 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; @@ -67,7 +70,7 @@ double pa_atod(const char* str, const St result=(double)strtod(str, &error_pos); 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,12 +152,11 @@ 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; - bool trim_start=(kind!=TRIM_END); - if(trim_start) { + // from left... + if(kind!=TRIM_END) { CORD_pos pos; set_pos(pos, 0); while(true) { char c=CORD_pos_fetch(pos); @@ -167,7 +169,20 @@ String::Body String::Body::trim(String:: CORD_next(pos); } } - // todo справа + // from right.. + if(kind!=TRIM_START) { + CORD_pos pos; set_pos(pos, end-1); + while(true) { + char c=CORD_pos_fetch(pos); + if(strchr(chars, c)) { + if(--end==0) // optimization: NO need to check for 'end>=start', that's(<) impossible + return 0; // all chars are empty, just return empty string + } else + break; + + CORD_prev(pos); + } + } if(start==0 && end==our_length) // nobody moved a thing return *this; @@ -657,7 +672,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(); @@ -693,4 +708,4 @@ const String& String::trim(String::Trim_ ASSERT_STRING_INVARIANT(result); return result; -} \ No newline at end of file +}