Diff for /parser3/src/classes/string.C between versions 1.63 and 1.69

version 1.63, 2001/07/18 10:06:04 version 1.69, 2001/08/02 09:58:33
Line 124  static void _lsplit(Request& r, const St Line 124  static void _lsplit(Request& r, const St
   
         Table& table=*new(pool) Table(pool, &string,           Table& table=*new(pool) Table(pool, &string, 
                 &columns, pieces.size());                  &columns, pieces.size());
         int size=pieces.quick_size();          Array_iter i(pieces);
         for(int i=0; i<size; i++) {          while(i.has_next()) {
                 Array& row=*new(pool) Array(pool);                  Array& row=*new(pool) Array(pool);
                 row+=pieces.quick_get(i);                  row+=i.next();
                 table+=&row;                  table+=&row;
         }          }
         r.write_no_lang(*new(pool) VTable(pool, &table));          r.write_no_lang(*new(pool) VTable(pool, &table));
Line 183  static void replace_action(Table& table, Line 183  static void replace_action(Table& table,
                         vtable.set_name(*ai.origin);                          vtable.set_name(*ai.origin);
   
                         Junction *junction=ai.replacement_code->get_junction();                          Junction *junction=ai.replacement_code->get_junction();
                         junction->rcontext=/*must be some way to get to                           Value *saved_match_var_value=junction->root->get_element(*match_var_name);
                                                            outside world junction->root=*/&vtable;                          junction->root->put_element(*match_var_name, &vtable);
                         Value& replaced=ai.request->process(*ai.replacement_code, ai.origin, false);                          Value& replaced=ai.request->process(*ai.replacement_code, ai.origin, false);
                           junction->root->put_element(*match_var_name, saved_match_var_value);
   
                         /*                          /*
                         ai.dest->APPEND_CONST("(");                          ai.dest->APPEND_CONST("(");
Line 214  static void _match(Request& r, const Str Line 215  static void _match(Request& r, const Str
         Temp_lang temp_lang(r, String::UL_PASS_APPENDED);          Temp_lang temp_lang(r, String::UL_PASS_APPENDED);
         Table *table;          Table *table;
         if(params->size()<3) { // search          if(params->size()<3) { // search
                   bool was_global;
                 bool matched=src.match(r.pcre_tables,                  bool matched=src.match(r.pcre_tables,
                         &method_name,                           &method_name, 
                         regexp.as_string(), options,                          regexp.as_string(), options,
                         &table,                          &table,
                         search_action, 0);                          search_action, 0,
                           &was_global);
                 // matched                  // matched
                 if(table->columns()->size()==3 && // just matched[3=pre/match/post], no substrings                  // not (just matched[3=pre/match/post], no substrings) or Global search
                         table->size()<=1)  // just one row, not /g_lobal search                  if(table->columns()->size()>3 || was_global) 
                         result=new(pool) VBool(pool, matched);                          result=new(pool) VTable(pool, table); // table of pre/match/post+substrings
                 else // table of pre/match/post+substrings                  else 
                         result=new(pool) VTable(pool, table);                          result=new(pool) VBool(pool, matched);                  
         } else { // replace          } else { // replace
                 Value& replacement_code=params->as_junction(2, "replacement code must be code");                  Value& replacement_code=params->as_junction(2, "replacement code must be code");
   
Line 261  static void _lower(Request& r, const Str Line 264  static void _lower(Request& r, const Str
         change_case(r, method_name, params, String::CC_LOWER);          change_case(r, method_name, params, String::CC_LOWER);
 }  }
   
   #ifndef DOXYGEN
   class String_sql_event_handlers : public SQL_Driver_query_event_handlers {
   public:
           String_sql_event_handlers(Pool& apool, 
                   const String& astatement_string, const char *astatement_cstr) :
                   pool(apool), 
                   statement_string(astatement_string),
                   statement_cstr(astatement_cstr),
                   got_column(false), got_cell(false) {
                   result=new(pool) String(pool);
           }
   
           void add_column(void *ptr, size_t size) {
                   if(got_column)
                           PTHROW(0, 0,
                                   &statement_string,
                                   "result must contain exactly one column");
                   got_column=true;
           }
           void before_rows() { /* ignore */ }
           void add_row() { /* ignore */ }
           void add_row_cell(void *ptr, size_t size) {
                   if(got_cell)
                           PTHROW(0, 0,
                                   &statement_string,
                                   "result must not contain more then one row");
                   got_cell=true;
   
                   result->APPEND_TAINTED((const char *)ptr, size, statement_cstr, 0);
           }
   
   private:
           Pool& pool;
           const String& statement_string; const char *statement_cstr;
           bool got_column;
   public:
           bool got_cell;
           String *result;
   };
   #endif
 const String* sql_result_string(Request& r, const String& method_name, MethodParams *params) {  const String* sql_result_string(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
   
Line 271  const String* sql_result_string(Request& Line 314  const String* sql_result_string(Request&
   
         Value& statement=params->as_junction(0, "statement must be code");          Value& statement=params->as_junction(0, "statement must be code");
   
         ulong offset=(ulong)(params->size()>2?params->as_int(2, r):0);  
   
         Temp_lang temp_lang(r, String::UL_SQL);          Temp_lang temp_lang(r, String::UL_SQL);
         const String& statement_string=r.process(statement).as_string();          const String& statement_string=r.process(statement).as_string();
         const char *statement_cstr=          const char *statement_cstr=
                 statement_string.cstr(String::UL_UNSPECIFIED, r.connection);                  statement_string.cstr(String::UL_UNSPECIFIED, r.connection);
         unsigned int sql_column_count; SQL_Driver::Cell *sql_columns;          String_sql_event_handlers handlers(pool, statement_string, statement_cstr);
         unsigned long sql_row_count; SQL_Driver::Cell **sql_rows;  
         bool need_rethrow=false; Exception rethrow_me;          bool need_rethrow=false; Exception rethrow_me;
         PTRY {          PTRY {
                 r.connection->query(                  r.connection->query(
                         statement_cstr, offset, 0,                          statement_cstr, 0, 0,
                         &sql_column_count, &sql_columns,                          handlers);
                         &sql_row_count, &sql_rows);  
         }          }
         PCATCH(e) { // query problem          PCATCH(e) { // query problem
                 rethrow_me=e;  need_rethrow=true;                  rethrow_me=e;  need_rethrow=true;
Line 295  const String* sql_result_string(Request& Line 334  const String* sql_result_string(Request&
                         &statement_string, // setting more specific source [were url]                          &statement_string, // setting more specific source [were url]
                         rethrow_me.comment());                          rethrow_me.comment());
                   
         if(sql_column_count!=1)          if(!handlers.got_cell)
                 PTHROW(0, 0,                  return 0; // no lines, caller should return second param[default value]
                         &statement_string,  
                         "result must contain exactly one column");  
   
         if(!sql_row_count)  
                 return 0; // no lines, should return second param[default value]  
   
         if(sql_row_count>1)          return handlers.result;
                 PTHROW(0, 0,  
                         &statement_string,  
                         "result must not contain more then one row");     
   
         String *result=new(pool) String(pool);  
         SQL_Driver::Cell& cell=sql_rows[0][0];  
         result->APPEND_TAINTED(  
                 (const char *)cell.ptr, cell.size,  
                 statement_cstr, 0);  
           
         return result;  
 }  }
   
 static void _sql(Request& r, const String& method_name, MethodParams *params) {  static void _sql(Request& r, const String& method_name, MethodParams *params) {
Line 322  static void _sql(Request& r, const Strin Line 345  static void _sql(Request& r, const Strin
   
         const String *string=sql_result_string(r, method_name, params);          const String *string=sql_result_string(r, method_name, params);
         if(!string) {          if(!string) {
                 Value& default_code=params->as_junction(1, "default result must code");                  if(params->size()>1) {
                 Value& processed_code=r.process(default_code);                          Value& default_code=params->as_junction(1, "default result must code");
                 string=processed_code.get_string();                          Value& processed_code=r.process(default_code);
                 if(!string)                          string=processed_code.get_string();
                         string=empty_string;                          if(!string)
                                   string=empty_string;
                   } else
                           PTHROW(0, 0,
                                   &method_name,
                                   "produced no result, but no default specified");
         }          }
         VString& result=*new(pool) VString(*string);          VString& result=*new(pool) VString(*string);
         result.set_name(method_name);          result.set_name(method_name);
Line 375  MString::MString(Pool& apool) : Methoded Line 403  MString::MString(Pool& apool) : Methoded
         // ^string.tolower[]          // ^string.tolower[]
         add_native_method("lower", Method::CT_DYNAMIC, _lower, 0, 0);          add_native_method("lower", Method::CT_DYNAMIC, _lower, 0, 0);
   
           // ^string:sql[query]
         // ^string:sql[query]{default}          // ^string:sql[query]{default}
         // ^string:sql[query]{default}(offset)          add_native_method("sql", Method::CT_STATIC, _sql, 1, 2);
         add_native_method("sql", Method::CT_STATIC, _sql, 2, 3);  
 }         }       
   
 // global variable  // global variable

Removed from v.1.63  
changed lines
  Added in v.1.69


E-mail: