--- parser3/src/classes/hash.C 2008/06/26 15:00:42 1.87 +++ parser3/src/classes/hash.C 2009/06/14 00:33:36 1.94 @@ -1,11 +1,11 @@ /** @file Parser: @b hash parser class. - Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HASH_C="$Date: 2008/06/26 15:00:42 $"; +static const char * const IDENT_HASH_C="$Date: 2009/06/14 00:33:36 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -22,7 +22,7 @@ static const char * const IDENT_HASH_C=" class MHash: public Methoded { public: // VStateless_class - Value* create_new_value(Pool&, HashStringValue&) { return new VHash(); } + Value* create_new_value(Pool&, HashStringValue*) { return new VHash(); } public: MHash(); @@ -74,9 +74,9 @@ public: empty(0) { } - bool add_column(SQL_Error& error, const char* str, size_t length) { + bool add_column(SQL_Error& error, const char* str, size_t) { try { - columns+=new String(str, length, true); + columns+=new String(str, String::L_TAINTED); return false; } catch(...) { error=SQL_Error("exception occured in Hash_sql_event_handlers::add_column"); @@ -113,11 +113,9 @@ public: return false; } - bool add_row_cell(SQL_Error& error, const char *ptr, size_t length) { + bool add_row_cell(SQL_Error& error, const char *ptr, size_t) { try { - String& cell=*new String; - if(length) - cell.append_know_length(ptr, length, String::L_TAINTED); + String& cell=*new String(ptr, String::L_TAINTED); bool duplicate=false; if(one_bool_column) { @@ -292,7 +290,7 @@ static void _intersects(Request& r, Meth result=GET_SELF(r, VHash).hash().first_that(intersects, b)!=0; // return result - r.write_no_lang(*new VBool(result)); + r.write_no_lang(VBool::get(result)); } @@ -324,13 +322,8 @@ static void _sql(Request& r, MethodParam bind=vbind->get_hash(); } if(Value* vlimit=options->get(sql_limit_name)) { - if(vlimit->is_defined()){ - valid_options++; - limit=(ulong)r.process_to_value(*vlimit).as_double(); - } else - throw Exception(PARSER_RUNTIME, - 0, - "limit must be defined"); + valid_options++; + limit=(ulong)r.process_to_value(*vlimit).as_double(); } if(Value* voffset=options->get(sql_offset_name)) { valid_options++; @@ -416,9 +409,8 @@ static void _delete(Request& r, MethodPa } static void _contains(Request& r, MethodParams& params) { - - bool result = GET_SELF(r, VHash).hash().contains(params.as_string(0, "key must be string")); - r.write_no_lang(*new VBool(result)); + bool result=GET_SELF(r, VHash).hash().contains(params.as_string(0, "key must be string")); + r.write_no_lang(VBool::get(result)); } #ifndef DOXYGEN @@ -434,10 +426,10 @@ struct Foreach_info { bool need_delim; }; #endif -static bool one_foreach_cycle( - HashStringValue::key_type akey, - HashStringValue::value_type avalue, - Foreach_info *info) { +static bool one_foreach_cycle( + HashStringValue::key_type akey, + HashStringValue::value_type avalue, + Foreach_info *info) { Value& var_context=*info->var_context; if(info->key_var_name){ info->vkey->set_string(*new String(akey, String::L_TAINTED)); @@ -446,20 +438,24 @@ static bool one_foreach_cycle( if(info->value_var_name) var_context.put_element(var_context, *info->value_var_name, avalue, false); - StringOrValue sv_processed=info->r->process(*info->body_code); - Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); - - const String* s_processed=sv_processed.get_string(); - if(info->delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body - if(info->need_delim) // need delim & iteration produced string? - info->r->write_pass_lang(info->r->process(*info->delim_maybe_code)); - else - info->need_delim=true; + if(info->delim_maybe_code){ // delimiter set + StringOrValue sv_processed=info->r->process(*info->body_code); + Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); + + const String* s_processed=sv_processed.get_string(); + if(s_processed && !s_processed->is_empty()) { // we have body + if(info->need_delim) // need delim & iteration produced string? + info->r->write_pass_lang(info->r->process(*info->delim_maybe_code)); + else + info->need_delim=true; + } + info->r->write_pass_lang(sv_processed); + return lskip==Request::SKIP_BREAK; + } else { + info->r->process_write(*info->body_code); + Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); + return lskip==Request::SKIP_BREAK; } - - info->r->write_pass_lang(sv_processed); - - return lskip==Request::SKIP_BREAK; } static void _foreach(Request& r, MethodParams& params) { Temp_hash_value