--- parser3/src/classes/string.C 2001/04/03 08:23:06 1.24 +++ parser3/src/classes/string.C 2001/04/03 14:38:58 1.26 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: string.C,v 1.24 2001/04/03 08:23:06 paf Exp $ + $Id: string.C,v 1.26 2001/04/03 14:38:58 paf Exp $ */ #include "pa_request.h" @@ -13,6 +13,7 @@ #include "pa_vdouble.h" #include "pa_vint.h" #include "pa_vtable.h" +#include "pa_vbool.h" // global var @@ -144,15 +145,31 @@ static void _match(Request& r, const Str // forcing {this param type} r.fail_if_junction_(false, regexp, method_name, "regexp must be junction"); - Value& options=*static_cast(params->get(1)); - // forcing {this param type} - r.fail_if_junction_(true, options, method_name, "options must not be junction"); + const String *options=0; + if(params->size()>1) { + Value& value=*static_cast(params->get(1)); + // forcing {this param type} + r.fail_if_junction_(true, value, method_name, "options must not be junction"); + options=&value.as_string(); + } Temp_lang temp_lang(r, String::UL_PASS_APPENDED); - Table& table=string.match(&method_name, - r.process(regexp).as_string(), options.as_string()); + Table *table; + Value *result; + if(string.match(&method_name, + r.process(regexp).as_string(), options, + &table)) { + // matched + if(table->columns()->size()==3 && // just matched[3=pre/match/post], no substrings + table->size()==1) // just one row, not Global search + result=new(pool) VBool(pool, true); + else // table of match column+substring columns + result=new(pool) VTable(pool, table); + } else // not global & not matched + result=new(pool) VBool(pool, false); - r.write_no_lang(*new(pool) VTable(pool, &table)); + result->set_name(method_name); + r.write_no_lang(*result); } // initialize @@ -186,6 +203,6 @@ void initialize_string_class(Pool& pool, vclass.add_native_method("rsplit", Method::CT_DYNAMIC, _rsplit, 1, 1); // ^string.match{regexp}[options] - vclass.add_native_method("match", Method::CT_DYNAMIC, _match, 2, 2); + vclass.add_native_method("match", Method::CT_DYNAMIC, _match, 1, 2); }