Diff for /parser3/src/classes/json.C between versions 1.67 and 1.68

version 1.67, 2025/05/26 00:52:15 version 1.68, 2025/10/05 19:41:27
Line 621  static void _string(Request& r, MethodPa Line 621  static void _string(Request& r, MethodPa
                 if(HashStringValue* options=params.as_hash(1)) {                  if(HashStringValue* options=params.as_hash(1)) {
                         json.params=&params[1];                          json.params=&params[1];
                         HashStringValue* methods=new HashStringValue();                          HashStringValue* methods=new HashStringValue();
                         int valid_options=0;  
                         HashStringValue* vvalue;                          HashStringValue* vvalue;
                         for(HashStringValue::Iterator i(*options); i; i.next() ){                          for(HashStringValue::Iterator i(*options); i; i.next() ){
                                 String::Body key=i.key();                                  String::Body key=i.key();
                                 Value* value=i.value();                                  Value* value=i.value();
                                 if(key == "skip-unknown"){                                  if(key == "skip-unknown"){
                                         json.skip_unknown=r.process(*value).as_bool();                                          json.skip_unknown=r.process(*value).as_bool();
                                         valid_options++;  
                                 } else if(key == "one-line"){                                  } else if(key == "one-line"){
                                         json.one_line=r.process(*value).as_bool();                                          json.one_line=r.process(*value).as_bool();
                                         valid_options++;  
                                 } else if(key == "date" && value->is_string()){                                  } else if(key == "date" && value->is_string()){
                                         const String& svalue=value->as_string();                                          const String& svalue=value->as_string();
                                         if(!json.set_date_format(svalue))                                          if(!json.set_date_format(svalue))
                                                 throw Exception(PARSER_RUNTIME, &svalue, "must be 'sql-string', 'gmt-string', 'iso-string' or 'unix-timestamp'");                                                  throw Exception(PARSER_RUNTIME, &svalue, "must be 'sql-string', 'gmt-string', 'iso-string' or 'unix-timestamp'");
                                         valid_options++;  
                                 } else if(key == "indent"){                                  } else if(key == "indent"){
                                         if(value->is_string()){                                          if(value->is_string()){
                                                 json.indent=value->as_string().cstr();                                                  json.indent=value->as_string().cstr();
                                                 json.json_string_recursion=strlen(json.indent);                                                  json.json_string_recursion=strlen(json.indent);
                                         } else json.indent=r.process(*value).as_bool() ? "" : NULL;                                          } else json.indent=r.process(*value).as_bool() ? "" : NULL;
                                         valid_options++;  
                                 } else if(key == "table" && value->is_string()){                                  } else if(key == "table" && value->is_string()){
                                         const String& svalue=value->as_string();                                          const String& svalue=value->as_string();
                                         if(!json.set_table_format(svalue))                                          if(!json.set_table_format(svalue))
                                                 throw Exception(PARSER_RUNTIME, &svalue, "must be 'array', 'object' or 'compact'");                                                  throw Exception(PARSER_RUNTIME, &svalue, "must be 'array', 'object' or 'compact'");
                                         valid_options++;  
                                 } else if(key == "array" && value->is_string()){                                  } else if(key == "array" && value->is_string()){
                                         const String& svalue=value->as_string();                                          const String& svalue=value->as_string();
                                         if(!json.set_array_format(svalue))                                          if(!json.set_array_format(svalue))
                                                 throw Exception(PARSER_RUNTIME, &svalue, "must be 'array', 'object' or 'compact'");                                                  throw Exception(PARSER_RUNTIME, &svalue, "must be 'array', 'object' or 'compact'");
                                         valid_options++;  
                                 } else if(key == "file" && value->is_string()){                                  } else if(key == "file" && value->is_string()){
                                         const String& svalue=value->as_string();                                          const String& svalue=value->as_string();
                                         if(!json.set_file_format(svalue))                                          if(!json.set_file_format(svalue))
                                                 throw Exception(PARSER_RUNTIME, &svalue, "must be 'base64', 'text' or 'stat'");                                                  throw Exception(PARSER_RUNTIME, &svalue, "must be 'base64', 'text' or 'stat'");
                                         valid_options++;  
                                 } else if(key == "void" && value->is_string()){                                  } else if(key == "void" && value->is_string()){
                                         const String& svalue=value->as_string();                                          const String& svalue=value->as_string();
                                         if(!json.set_void_format(svalue))                                          if(!json.set_void_format(svalue))
                                                 throw Exception(PARSER_RUNTIME, &svalue, "must be 'string' or 'null'");                                                  throw Exception(PARSER_RUNTIME, &svalue, "must be 'string' or 'null'");
                                         valid_options++;  
 #ifdef XML  #ifdef XML
                                 } else if(key == "xdoc" && (vvalue = value->get_hash())){                                  } else if(key == "xdoc" && (vvalue = value->get_hash())){
                                         json.xdoc_options=new XDocOutputOptions();                                          json.xdoc_options=new XDocOutputOptions();
                                         json.xdoc_options->append(r, vvalue);                                          json.xdoc_options->append(r, vvalue);
                                         valid_options++;  
 #endif  #endif
                                 } else if(Junction* junction=value->get_junction()){                                  } else if(Junction* junction=value->get_junction()){
                                         if(!junction->method || !junction->method->params_names || junction->method->params_count != 3)                                          if(!junction->method || !junction->method->params_names || junction->method->params_count != 3)
                                                 throw Exception(PARSER_RUNTIME, 0, "$.%s must be parser method with 3 parameters", key.cstr());                                                  throw Exception(PARSER_RUNTIME, 0, "$.%s must be parser method with 3 parameters", key.cstr());
                                         methods->put(key, value);                                          methods->put(key, value);
                                         valid_options++;                                  } else
                                 }                                          throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
                         }                          }
   
                         if(valid_options!=options->count())  
                                 throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);  
   
                         // special handling for $._default                           // special handling for $._default 
                         if(VHashBase* vhash=dynamic_cast<VHashBase*>(&params[1]))                          if(VHashBase* vhash=dynamic_cast<VHashBase*>(&params[1]))
                                 if(Value* value=vhash->get_default()) {                                  if(Value* value=vhash->get_default()) {

Removed from v.1.67  
changed lines
  Added in v.1.68


E-mail: