--- parser3/src/classes/table.C 2001/09/06 06:11:13 1.110 +++ parser3/src/classes/table.C 2001/10/09 08:13:04 1.121 @@ -2,10 +2,10 @@ Parser: @b table parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: table.C,v 1.121 2001/10/09 08:13:04 parser Exp $ */ -static const char *RCSId="$Id: table.C,v 1.110 2001/09/06 06:11:13 parser Exp $"; #include "classes.h" #include "pa_config_includes.h" @@ -65,7 +65,7 @@ static void _set(Request& r, const Strin while(i.has_next()) { Array& row=*new(pool) Array(pool); const String& string=*i.next_string(); - // remove empty lines + // remove comment lines if(!string.size()) continue; @@ -110,7 +110,8 @@ static void _load(Request& r, const Stri Table& table=*new(pool) Table(pool, &method_name, columns); char *row_chars; while(row_chars=getrow(&data)) { - if(!*row_chars) // remove empty lines + // remove empty&comment lines + if(!*row_chars || *row_chars == '#') continue; Array *row=new(pool) Array(pool); while(char *cell_chars=lsplit(&row_chars, '\t')) { @@ -133,8 +134,8 @@ static Table *fill_month_days(Request& r Pool& pool=r.pool(); Table *result=new(pool) Table(pool, &method_name, 0/*&columns*/); - int year=params->as_int(1, r); - int month=max(1, min(params->as_int(2, r), 12)) -1; + int year=params->as_int(1, "year must be int", r); + int month=max(1, min(params->as_int(2, "month must be int", r), 12)) -1; tm tmIn={0, 0, 0, 1, month, year-1900}; time_t t=mktime(&tmIn); @@ -176,9 +177,9 @@ static Table *fill_week_days(Request& r, columns+=new(pool) String(pool, "weekday"); Table *result=new(pool) Table(pool, &method_name, &columns); - int year=params->as_int(1, r); - int month=max(1, min(params->as_int(2, r), 12)) -1; - int day=params->as_int(3, r); + int year=params->as_int(1, "year must be int", r); + int month=max(1, min(params->as_int(2, "month must be int", r), 12)) -1; + int day=params->as_int(3, "day must be int", r); tm tmIn={0, 0, 18, day, month, year-1900}; time_t t=mktime(&tmIn); @@ -320,7 +321,7 @@ static void _offset(Request& r, const St static void _menu(Request& r, const String& method_name, MethodParams *params) { Value& body_code=params->as_junction(0, "body must be code"); - Value *delim_code=params->size()==2?¶ms->get(1):0; + Value *delim_maybe_code=params->size()==2?¶ms->get(1):0; VTable& vtable=*static_cast(r.self); Table& table=vtable.table(); @@ -331,10 +332,10 @@ static void _menu(Request& r, const Stri table.set_current(row); Value& processed_body=r.process(body_code); - if(delim_code) { // delimiter set? + if(delim_maybe_code) { // delimiter set? const String *string=processed_body.get_string(); if(need_delim && string && string->size()) // need delim & iteration produced string? - r.write_pass_lang(r.process(*delim_code)); + r.write_pass_lang(r.process(*delim_maybe_code)); need_delim=true; } r.write_pass_lang(processed_body); @@ -342,13 +343,6 @@ static void _menu(Request& r, const Stri table.set_current(saved_current); } -static void _empty(Request& r, const String& method_name, MethodParams *params) { - Pool& pool=r.pool(); - Table& table=static_cast(r.self)->table(); - - r.write_no_lang(*new(pool) VBool(pool, table.size()==0)); -} - #ifndef DOXYGEN struct Row_info { Table *table; @@ -477,7 +471,8 @@ static void _sort(Request& r, const Stri for(i=0; i(r.self)->set_table(new_table); } static void _locate(Request& r, const String& method_name, MethodParams *params) { @@ -486,8 +481,9 @@ static void _locate(Request& r, const St VTable& vtable=*static_cast(r.self); Table& table=vtable.table(); Value& result=*new(pool) VBool(pool, table.locate( - params->get(0).as_string(), - params->get(1).as_string())); + params->as_string(0, "column name must be string"), + params->as_string(1, "value must be string") + )); result.set_name(method_name); r.write_no_lang(result); } @@ -718,9 +714,6 @@ MTable::MTable(Pool& apool) : Methoded(a // ^table.menu{code}[delim] add_native_method("menu", Method::CT_DYNAMIC, _menu, 1, 2); - // ^table.empty[] - add_native_method("empty", Method::CT_DYNAMIC, _empty, 0, 0); - // ^table:hash[key field name] // ^table:hash[key field name][value field name;...] add_native_method("hash", Method::CT_DYNAMIC, _hash, 1, 1000);