--- parser3/src/classes/table.C 2001/03/28 08:01:40 1.36 +++ parser3/src/classes/table.C 2001/03/29 15:00:19 1.38 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: table.C,v 1.36 2001/03/28 08:01:40 paf Exp $ + $Id: table.C,v 1.38 2001/03/29 15:00:19 paf Exp $ */ #include "pa_config_includes.h" @@ -63,7 +63,7 @@ static void set_or_load( if(char *row_chars=getrow(&data)) do { String *name=new(pool) String(pool); - name->APPEND(lsplit(&row_chars, '\t'), 0, file, line++); + name->APPEND_CLEAN(lsplit(&row_chars, '\t'), 0, file, line++); *columns+=name; } while(row_chars); } @@ -77,7 +77,7 @@ static void set_or_load( Array *row=new(pool) Array(pool); while(char *cell_chars=lsplit(&row_chars, '\t')) { String *cell=new(pool) String(pool); - cell->APPEND(cell_chars, 0, file, line); + cell->APPEND_CLEAN(cell_chars, 0, file, line); *row+=cell; } line++; @@ -159,21 +159,17 @@ static void _count(Request& r, const Str static void _line(Request& r, const String&, Array *) { Pool& pool=r.pool(); - Value& value=*new(pool) VInt(pool, 1+static_cast(r.self)->table().get_current()); + Value& value=*new(pool) VInt(pool, 1+static_cast(r.self)->table().current()); r.write_no_lang(value); } static void _offset(Request& r, const String&, Array *params) { Pool& pool=r.pool(); Table& table=static_cast(r.self)->table(); - if(params->size()) { - if(int size=table.size()) { - int offset= - (int)r.process(*static_cast(params->get(0))).as_double(); - table.set_current((table.get_current()+offset+size)%size); - } - } else { - Value& value=*new(pool) VInt(pool, table.get_current()); + if(params->size()) + table.shift((int)r.process(*static_cast(params->get(0))).as_double()); + else { + Value& value=*new(pool) VInt(pool, table.current()); r.write_no_lang(value); } } @@ -188,6 +184,7 @@ static void _menu(Request& r, const Stri Table& table=static_cast(r.self)->table(); bool need_delim=false; + int saved_current=table.current(); for(int row=0; row(params->get(1))->as_string()); } +static void _found(Request& r, const String& method_name, Array *params) { + if(static_cast(r.self)->last_locate_was_successful) { + Value& then_code=*static_cast(params->get(0)); + // forcing ^found{this param type} + r.fail_if_junction_(false, then_code, + method_name, "found-parameter must be junction"); + r.write_pass_lang(r.process(then_code)); + } else if(params->size()==2) { + Value& else_code=*static_cast(params->get(1)); + // forcing ^found{this param type} + r.fail_if_junction_(false, else_code, + method_name, "not found-parameter must be junction"); + r.write_pass_lang(r.process(else_code)); + } +} + // initialize void initialize_table_class(Pool& pool, VStateless_class& vclass) { @@ -364,4 +378,7 @@ void initialize_table_class(Pool& pool, // ^table.locate[field;value] vclass.add_native_method("locate", _locate, 2, 2); + // ^table.found{when-found} + // ^table.found{when-found}{when-not-found} + vclass.add_native_method("found", _found, 1, 2); }