--- parser3/src/main/pa_string.C 2016/12/28 17:41:15 1.258 +++ parser3/src/main/pa_string.C 2023/09/26 20:49:10 1.269 @@ -1,8 +1,8 @@ /** @file Parser: string class. @see untalength_t.C. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #include "pa_string.h" @@ -12,14 +12,13 @@ #include "pa_charset.h" #include "pa_vregex.h" -#ifndef ULLONG_MAX -#define ULLONG_MAX 18446744073709551615ULL -#endif - -volatile const char * IDENT_PA_STRING_C="$Id: pa_string.C,v 1.258 2016/12/28 17:41:15 moko Exp $" IDENT_PA_STRING_H; +volatile const char * IDENT_PA_STRING_C="$Id: pa_string.C,v 1.269 2023/09/26 20:49:10 moko Exp $" IDENT_PA_STRING_H; const String String::Empty; +#define COMPILE_ASSERT(x) extern int assert_checker[(x) ? 1 : -1] +COMPILE_ASSERT(sizeof(String::Languages) == sizeof(CORD)); + // pa_atoui is based on Manuel Novoa III _strto_l for uClibc template inline T pa_ato_any(const char *str, int base, const String* problem_source,const T max){ @@ -87,14 +86,20 @@ template inline T pa_ato_any } unsigned int pa_atoui(const char *str, int base, const String* problem_source){ + if(!str) + return 0; + return pa_ato_any(str, base, problem_source, UINT_MAX); } -unsigned long long pa_atoul(const char *str, int base, const String* problem_source){ - return pa_ato_any(str, base, problem_source, ULLONG_MAX); +uint64_t pa_atoul(const char *str, int base, const String* problem_source){ + if(!str) + return 0; + + return pa_ato_any(str, base, problem_source, ULLONG_MAX); } -int pa_atoi(const char* str, const String* problem_source) { +int pa_atoi(const char* str, int base, const String* problem_source) { if(!str) return 0; @@ -112,7 +117,7 @@ int pa_atoi(const char* str, const Strin str++; } - unsigned int result=pa_atoui(str, 0, problem_source); + unsigned int result=pa_atoui(str, base, problem_source); if(negative && result <= ((unsigned int)(-(1+INT_MIN)))+1) return -(int)result; @@ -656,6 +661,7 @@ Table* String::match(VRegex* vregex, Row int prestart=0; int poststart=0; int postfinish=length(); + int action_was_executed=-1; while(true) { int exec_result=vregex->exec(subject, subject_length, ovector, ovector_size, prestart); @@ -665,8 +671,9 @@ Table* String::match(VRegex* vregex, Row int prefinish=ovector[0]; poststart=ovector[1]; - if (prestart==poststart && subject[poststart]=='\n'){ + if (prestart==poststart && action_was_executed==1){ prestart++; + action_was_executed=0; continue; } @@ -687,12 +694,13 @@ Table* String::match(VRegex* vregex, Row } matches_count++; - row_action(table, row, prestart, prefinish, poststart, postfinish, info); + row_action(table, row, prestart - !action_was_executed, prefinish, poststart, postfinish, info); - if(!global || prestart==poststart) // last step + if(!global || poststart>=subject_length) // last step, avoid prestart++ after last char break; prestart=poststart; + action_was_executed=1; } row_action(table, 0/*last time, no raw*/, 0, 0, poststart, postfinish, info);