--- parser3/src/main/pa_common.C 2025/07/04 00:18:35 1.340 +++ parser3/src/main/pa_common.C 2026/04/24 20:14:33 1.342 @@ -8,6 +8,7 @@ #include "pa_common.h" #include "pa_exception.h" #include "pa_hash.h" +#include "pa_inline_hash.h" #include "pa_globals.h" #include "pa_charsets.h" #include "pa_http.h" @@ -22,7 +23,7 @@ #include #endif -volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.340 2025/07/04 00:18:35 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; +volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.342 2026/04/24 20:14:33 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_INLINE_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; // some maybe-undefined constants @@ -697,100 +698,6 @@ const char *pa_filename(const char *path return path; } -// format: %[flags][width][.precision]type http://msdn.microsoft.com/ru-ru/library/56e442dc(en-us,VS.80).aspx -// flags: '-', '+', ' ', '#', '0' http://msdn.microsoft.com/ru-ru/library/8aky45ct(en-us,VS.80).aspx -// width, precision: non negative decimal number -enum FormatType { - FormatInvalid, - FormatInt, - FormatUInt, - FormatDouble -}; -FormatType format_type(const char* fmt){ - enum FormatState { - Percent, - Flags, - Width, - Precision, - Done - } state=Percent; - - FormatType result=FormatInvalid; - - const char* pos=fmt; - while(char c=*(pos++)){ - switch(state){ - case Percent: - if(c=='%'){ - state=Flags; - } else { - return FormatInvalid; // 1st char must be '%' only - } - break; - case Flags: - if(strchr("-+ #0", c)!=0){ - break; - } - // go to the next step - case Width: - if(c=='.'){ - state=Precision; - break; - } - // go to the next step - case Precision: - if(c>='0' && c<='9'){ - if(state == Flags) state=Width; // no more flags - break; - } else if(c=='d' || c=='i'){ - result=FormatInt; - } else if(strchr("feEgG", c)!=0){ - result=FormatDouble; - } else if(strchr("uoxX", c)!=0){ - result=FormatUInt; - } else { - return FormatInvalid; // invalid char - } - state=Done; - break; - case Done: - return FormatInvalid; // no chars allowed after 'type' - } - } - return result; -} - - -const char* format_double(double value, const char* fmt) { - char local_buf[MAX_NUMBER]; - int size=-1; - - if(fmt && strlen(fmt)){ - switch(format_type(fmt)){ - case FormatDouble: - size=snprintf(local_buf, sizeof(local_buf), fmt, value); - break; - case FormatUInt: - if(value >= 0){ // on Apple M1 (uint) is 0 - size=snprintf(local_buf, sizeof(local_buf), fmt, clip2uint(value)); - break; - } - case FormatInt: - size=snprintf(local_buf, sizeof(local_buf), fmt, clip2int(value)); - break; - case FormatInvalid: - throw Exception(PARSER_RUNTIME, 0, "Incorrect format string '%s' was specified.", fmt); - } - } else - return pa_itoa(clip2int(value)); - - if(size < 0 || size >= MAX_NUMBER-1){ // on win32 we manually reduce max size while printing - throw Exception(PARSER_RUNTIME, 0, "Error occurred white executing snprintf with format string '%s'.", fmt); - } - - return pa_strdup(local_buf, (size_t)size); -} - size_t stdout_write(const void *buf, size_t size) { #ifdef WIN32 size_t to_write = size; @@ -812,8 +719,8 @@ size_t stdout_write(const void *buf, siz } enum EscapeState { - EscapeRest, - EscapeFirst, + EscapeRest, + EscapeFirst, EscapeSecond, EscapeUnicode };