--- parser3/src/classes/string.C 2002/04/18 10:51:00 1.103 +++ parser3/src/classes/string.C 2002/04/19 08:54:35 1.105 @@ -4,7 +4,7 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - $Id: string.C,v 1.103 2002/04/18 10:51:00 paf Exp $ + $Id: string.C,v 1.105 2002/04/19 08:54:35 paf Exp $ */ #include "classes.h" @@ -172,7 +172,7 @@ static void _rsplit(Request& r, const St r.write_no_lang(*new(pool) VTable(pool, &table)); } -static void search_action(Table& table, Array *row, int, int, void *) { +static void search_action(Table& table, Array *row, int, int, int, int, void *) { if(row) table+=row; } @@ -181,41 +181,32 @@ static void search_action(Table& table, struct Replace_action_info { Request *request; const String *origin; const String *src; String *dest; + VTable *vtable; Value *replacement_code; - const String *post_match; }; #endif -static void replace_action(Table& table, Array *row, int start, int finish, - void *info) { +/// @todo they can do $global[$result] there, getting pointer to later-invalid local var, kill this +static void replace_action(Table& table, Array *row, + int prestart, int prefinish, + int poststart, int postfinish, + void *info) { Replace_action_info& ai=*static_cast(info); if(row) { // begin&middle - // piece from last match['start'] to beginning of this match['finish'] - if(start!=finish) - *ai.dest << ai.src->mid(start, finish);//ai.dest->APPEND_CONST("-"); + // piece from last match['prestart'] to beginning of this match['prefinish'] + if(prestart!=prefinish) + *ai.dest << ai.src->mid(prestart, prefinish);//ai.dest->APPEND_CONST("-"); // store found parts in one-record VTable if(table.size()) // middle table.put(0, row); else // begin table+=row; { // execute 'replacement_code' in 'table' context - VTable& vtable=*new(table.pool()) VTable(table.pool(), &table); + ai.vtable->set_table(table); - Junction *junction=ai.replacement_code->get_junction(); - Value *saved_match_var_value=junction->root->get_element(*match_var_name); - junction->root->put_element(*match_var_name, &vtable); - const String& replaced=ai.request->process_to_string(*ai.replacement_code); - junction->root->put_element(*match_var_name, saved_match_var_value); - - /* - ai.dest->APPEND_CONST("("); - *ai.dest << *(String *)row->get(1/*match* /); - ai.dest->APPEND_CONST(")"); - */ - *ai.dest << replaced; + *ai.dest << ai.request->process_to_string(*ai.replacement_code); } - ai.post_match=(String *)row->get(2/*post_match*/); } else // end - *ai.dest << *ai.post_match; + *ai.dest << ai.src->mid(poststart, postfinish); } /// @todo use pcre:study somehow @@ -243,7 +234,7 @@ static void _match(Request& r, const Str // matched // not (just matched[3=pre/match/post], no substrings) or Global search if(table->columns()->size()>3 || was_global) - result=new(pool) VTable(pool, table); // table of pre/match/post+substrings + result=new(pool) VTable(pool, table/*TODO: clone this when table would be stacked!*/); // table of pre/match/post+substrings else result=new(pool) VBool(pool, matched); r.write_assign_lang(*result); @@ -251,12 +242,16 @@ static void _match(Request& r, const Str Value& replacement_code=params->as_junction(2, "replacement param must be code"); String& result=*new(pool) String(pool); + VTable vtable(pool); Replace_action_info replace_action_info={ &r, &method_name, &src, &result, - &replacement_code, - &src + &vtable, + &replacement_code }; + Temp_value_element temp_match_var( + *replacement_code.get_junction()->root, + *match_var_name, &vtable); src.match( &method_name, r.process_to_string(regexp), options,