Diff for /parser3/src/classes/op.C between versions 1.258 and 1.268

version 1.258, 2020/11/10 22:42:24 version 1.268, 2024/11/10 20:46:08
Line 1 Line 1
 /** @file  /** @file
         Parser: parser @b operators.          Parser: parser @b operators.
   
         Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #include "classes.h"  #include "classes.h"
Line 76  public: Line 76  public:
                 ULN("json", JSON);                  ULN("json", JSON);
                 #undef ULN                  #undef ULN
         }          }
 } untaint_lang_name2enum;  
           static Untaint_lang_name2enum &instance(){
                   static Untaint_lang_name2enum *singleton=NULL;
                   if(!singleton)
                           singleton=new Untaint_lang_name2enum;
                   return *singleton;
           }
   
   };
   
 // methods  // methods
   
Line 97  static void _if(Request& r, MethodParams Line 105  static void _if(Request& r, MethodParams
 }  }
   
 String::Language get_untaint_lang(const String& lang_name){  String::Language get_untaint_lang(const String& lang_name){
         String::Language lang=untaint_lang_name2enum.get(lang_name);          String::Language lang=Untaint_lang_name2enum::instance().get(lang_name);
         if(!lang)          if(!lang)
                 throw Exception(PARSER_RUNTIME, &lang_name, "invalid taint language");                  throw Exception(PARSER_RUNTIME, &lang_name, "invalid taint language");
         return lang;          return lang;
Line 401  static void _eval(Request& r, MethodPara Line 409  static void _eval(Request& r, MethodPara
                 if(fmt.is_empty()){                  if(fmt.is_empty()){
                         r.write(value_result);                          r.write(value_result);
                 } else {                  } else {
                         r.write(String(format(value_result.as_double(), fmt.cstrm())));                          r.write(String(format_double(value_result.as_double(), fmt.cstrm())));
                 }                  }
         } else          } else
                 r.write(value_result);                  r.write(value_result);
Line 729  static Cache_get_result cache_get(Reques Line 737  static Cache_get_result cache_get(Reques
   
 static time_t as_expires(Request& r, MethodParams& params, int index, time_t now) {  static time_t as_expires(Request& r, MethodParams& params, int index, time_t now) {
         time_t result;          time_t result;
         if(Value* vdate=params[index].as(VDATE_TYPE))          if(VDate* vdate=dynamic_cast<VDate*>(&params[index]))
                 result=(time_t)(static_cast<VDate*>(vdate)->get_time());                  result=vdate->get_time();
         else          else
                 result=now+(time_t)params.as_double(index, "lifespan must be date or number", r);                  result=now+(time_t)params.as_double(index, "lifespan must be date or number", r);
                   
Line 861  static void _try_operator(Request& r, Me Line 869  static void _try_operator(Request& r, Me
                 // no exception in try/catch, writing processed body_code or catch_code                  // no exception in try/catch, writing processed body_code or catch_code
                 r.write(result.processed_code);                  r.write(result.processed_code);
         }          }
   
 }  }
   
 static void _throw_operator(Request&, MethodParams& params) {  static void _throw_operator(Request&, MethodParams& params) {
Line 877  static void _throw_operator(Request&, Me Line 884  static void _throw_operator(Request&, Me
                         if(Value* value=hash->get(exception_comment_part_name))                          if(Value* value=hash->get(exception_comment_part_name))
                                 comment=value->as_string().cstr();                                  comment=value->as_string().cstr();
   
                         throw Exception(type,                          throw Exception(type, source, "%s", comment); // to avoid MAX_STRING limit
                                 source?source:0,  
                                 "%s", comment?comment:"");  
                 } else                  } else
                         throw Exception(PARSER_RUNTIME,                          throw Exception(PARSER_RUNTIME, 0, "one-param version has hash or string param");
                                 0,  
                                 "one-param version has hash or string param");  
         } else {          } else {
                 const char* type=params.as_string(0, "type must be string").cstr();                  const char* type=params.as_string(0, "type must be string").cstr();
                 const String* source=params.count()>1? &params.as_string(1, "source must be string"):0;                  const String* source=params.count()>1 ? &params.as_string(1, "source must be string") : 0;
                 const char* comment=params.count()>2? params.as_string(2, "comment must be string").cstr():0;                  const char* comment=params.count()>2 ? params.as_string(2, "comment must be string").cstr() : 0;
                 throw Exception(type, source, "%s", comment?comment:"");                  throw Exception(type, source, "%s", comment); // to avoid MAX_STRING limit
         }          }
  }  }
   
 static void _sleep_operator(Request& r, MethodParams& params) {  static void _sleep_operator(Request& r, MethodParams& params) {
         double seconds=params.as_double(0, "seconds must be double", r);          double seconds=params.as_double(0, "seconds must be double", r);
         if(seconds>0)          if(seconds>0)
                 pa_sleep((int)trunc(seconds), (int)trunc((seconds-trunc(seconds))*1000000));                  pa_sleep((int)trunc(seconds), (int)trunc((seconds-trunc(seconds))*1000000));
  }  }
   
 #if defined(WIN32) && defined(_DEBUG) && !defined(_WIN64)  #if defined(WIN32) && defined(_DEBUG) && !defined(_WIN64)
 #       define PA_BPT  #       define PA_BPT

Removed from v.1.258  
changed lines
  Added in v.1.268


E-mail: