--- parser3/src/classes/string.C 2005/08/26 12:01:38 1.145 +++ parser3/src/classes/string.C 2007/01/18 17:48:15 1.150 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_STRING_C="$Date: 2005/08/26 12:01:38 $"; +static const char * const IDENT_STRING_C="$Date: 2007/01/18 17:48:15 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -323,12 +323,13 @@ static void _match(Request& r, MethodPar regexp.as_string(), options, search_action, 0, just_matched); - Value* result; - if(table) - result=new VTable(table); // table of pre/match/post+substrings - else - result=new VBool(just_matched); - r.write_assign_lang(*result); + // Value* result; + // if(table) + // result=new VTable(table); // table of pre/match/post+substrings + // else + // result=new VBool(just_matched); + // r.write_assign_lang(*result); + r.write_assign_lang(*new VTable(table)); } else { // replace Value& replacement_code=params.as_junction(2, "replacement param must be code"); @@ -446,10 +447,6 @@ const String* sql_result_string(Request& } if((default_code=options->get(sql_default_name))) { valid_options++; - if(!default_code->get_junction()) - throw Exception("parser.runtime", - 0, - "default option must be code"); } if(valid_options!=options->count()) throw Exception("parser.runtime", @@ -587,6 +584,24 @@ static void _append(Request& r, MethodPa va.set_string(c); } +static void _base64(Request& r, MethodParams& params) { + if(params.count()) { + // decode + const char* cstr=params.as_string(0, "parameter must be string").cstr(); + char* decoded_cstr=0; + size_t decoded_size=0; + pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size); + if(decoded_cstr && decoded_size) + r.write_assign_lang(*new String(decoded_cstr, decoded_size, true)); + } else { + // encode + VString& self=GET_SELF(r, VString); + const char* cstr=self.string().cstr(); + const char* encoded=pa_base64_encode(cstr, strlen(cstr)); + r.write_assign_lang(*new String(encoded, 0, true/*once ?param=base64(something) was needed*/)); + } +} + // constructor MString::MString(): Methoded("string") { @@ -649,4 +664,8 @@ MString::MString(): Methoded("string") { // ^string.append[string] add_native_method("append", Method::CT_DYNAMIC, _append, 1, 1); + + // ^string.base64[] << encode + // ^string:base64[encoded string] << decode + add_native_method("base64", Method::CT_ANY, _base64, 0, 1); }