--- parser3/src/main/pa_string.C 2004/02/27 15:07:46 1.195 +++ parser3/src/main/pa_string.C 2004/04/02 13:57:07 1.197 @@ -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/04/02 13:57:07 $"; #include "pcre.h" @@ -32,8 +32,11 @@ 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); @@ -153,8 +156,8 @@ String::Body String::Body::trim(String:: 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 +170,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;