--- parser3/src/classes/string.C 2011/05/19 06:58:40 1.199 +++ parser3/src/classes/string.C 2012/01/08 05:58:27 1.201 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_STRING_C="$Date: 2011/05/19 06:58:40 $"; +static const char * const IDENT_STRING_C="$Date: 2012/01/08 05:58:27 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -554,8 +554,7 @@ const String* sql_result_string(Request& } if(valid_options!=options->count()) throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); - } else - throw Exception(PARSER_RUNTIME, 0, OPTIONS_MUST_BE_HASH); + } else options=0; @@ -606,14 +605,24 @@ static void _sql(Request& r, MethodParam static void _replace(Request& r, MethodParams& params) { const String& src=GET_SELF(r, VString).string(); - Table* table=params.as_no_junction(0, PARAM_MUST_NOT_BE_CODE).get_table(); - if(!table) - throw Exception(PARSER_RUNTIME, - 0, - "parameter must be table"); + if(params.count()==1) { + // ^string.replace[table] + Table* table=params.as_no_junction(0, PARAM_MUST_NOT_BE_CODE).get_table(); + if(!table) + throw Exception(PARSER_RUNTIME, + 0, + "parameter must be table"); + Dictionary dict(*table); + r.write_assign_lang(src.replace(dict)); + } else { + // ^string.replace[from-string;to-string] + Dictionary dict( + params.as_string(0, "from must be string"), + params.as_string(1, "to must be string") + ); + r.write_assign_lang(src.replace(dict)); + } - Dictionary dict(*table); - r.write_assign_lang(src.replace(dict)); } static void _save(Request& r, MethodParams& params) { @@ -783,7 +792,7 @@ MString::MString(): Methoded("string") { add_native_method("sql", Method::CT_STATIC, _sql, 1, 2); // ^string.replace[table] - add_native_method("replace", Method::CT_DYNAMIC, _replace, 1, 1); + add_native_method("replace", Method::CT_DYNAMIC, _replace, 1, 2); // ^string.save[append][file] // ^string.save[file]