--- parser3/src/classes/table.C 2002/01/16 10:28:34 1.138 +++ parser3/src/classes/table.C 2002/02/07 11:55:30 1.142 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: table.C,v 1.138 2002/01/16 10:28:34 paf Exp $ + $Id: table.C,v 1.142 2002/02/07 11:55:30 paf Exp $ */ #include "classes.h" @@ -34,8 +34,15 @@ public: // Methoded // methods -static void _set(Request& r, const String& method_name, MethodParams *params) { +static void _create(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); + // clone? + if(params->size()==1) + if(const Table *source=params->get(0).get_table()) { + static_cast(r.self)->set_table(*new(pool) Table(*source)); + return; + } + // data is last parameter Temp_lang temp_lang(r, String::UL_PASS_APPENDED); const String& data= @@ -92,16 +99,22 @@ static void _load(Request& r, const Stri uint line=origin.line; #endif if(params->size()==2) { - columns=0; + columns=0; // nameless } else { columns=new(pool) Array(pool); - if(char *row_chars=getrow(&data)) + while(char *row_chars=getrow(&data)) { + // remove empty&comment lines + if(!*row_chars || *row_chars == '#') + continue; do { String *name=new(pool) String(pool); name->APPEND_TAINTED(lsplit(&row_chars, '\t'), 0, file, line++); *columns+=name; } while(row_chars); + + break; + } } // parse cells @@ -184,7 +197,7 @@ static void _save(Request& r, const Stri } // write - file_write(pool, r.absolute(vfile_name.as_string()), + file_write(r.absolute(vfile_name.as_string()), sdata.cstr(), sdata.size(), true, do_append); } @@ -458,8 +471,10 @@ static void _join(Request& r, const Stri for(int src_row=0; src_rowsize(); dest_column++) - dest_row+=src.item(*dest_columns->get_string(dest_column)); + for(int dest_column=0; dest_columnsize(); dest_column++) { + const String *src_item=src.item(*dest_columns->get_string(dest_column)); + dest_row+=src_item?src_item:new(pool) String(pool); + } dest+=&dest_row; } src.set_current(saved_src_current); @@ -605,12 +620,15 @@ static void _columns(Request& r, const S MTable::MTable(Pool& apool) : Methoded(apool) { set_name(*NEW String(pool(), TABLE_CLASS_NAME)); - // ^table:set{data} - // ^table:set[nameless]{data} - add_native_method("set", Method::CT_DYNAMIC, _set, 1, 2); + // ^table::create{data} + // ^table::create[nameless]{data} + // ^table::create[table] + add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2); + // old name for compatibility with <= v 1.141 2002/01/25 11:33:45 paf + add_native_method("set", Method::CT_DYNAMIC, _create, 1, 2); - // ^table:load[file] - // ^table:load[nameless;file] + // ^table::load[file] + // ^table::load[nameless;file] add_native_method("load", Method::CT_DYNAMIC, _load, 1, 2); // ^table.save[file]