Diff for /parser3/src/classes/table.C between versions 1.112 and 1.120

version 1.112, 2001/09/18 16:05:42 version 1.120, 2001/10/09 07:06:00
Line 2 Line 2
         Parser: @b table parser class.          Parser: @b table parser class.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
   
         Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)          Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
   
           $Id$
 */  */
 static const char *RCSId="$Id$";   
   
 #include "classes.h"  #include "classes.h"
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
Line 65  static void _set(Request& r, const Strin Line 65  static void _set(Request& r, const Strin
         while(i.has_next()) {          while(i.has_next()) {
                 Array& row=*new(pool) Array(pool);                  Array& row=*new(pool) Array(pool);
                 const String& string=*i.next_string();                  const String& string=*i.next_string();
                 // remove empty lines                  // remove comment lines
                 if(!string.size())                  if(!string.size())
                         continue;                          continue;
   
Line 80  static void _set(Request& r, const Strin Line 80  static void _set(Request& r, const Strin
 static void _load(Request& r, const String& method_name, MethodParams *params) {  static void _load(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         // filename is last parameter          // filename is last parameter
         const String& filename=params->as_string(params->size()-1,           Value& vfilename=params->as_no_junction(params->size()-1, 
                 "file name must not be code");                  "file name must not be code");
   
         // loading text          // loading text
         char *data=file_read_text(pool, r.absolute(filename));          char *data=file_read_text(pool, r.absolute(vfilename.as_string()));
   
         // parse columns          // parse columns
         Array *columns;          Array *columns;
Line 110  static void _load(Request& r, const Stri Line 110  static void _load(Request& r, const Stri
         Table& table=*new(pool) Table(pool, &method_name, columns);          Table& table=*new(pool) Table(pool, &method_name, columns);
         char *row_chars;          char *row_chars;
         while(row_chars=getrow(&data)) {          while(row_chars=getrow(&data)) {
                 if(!*row_chars) // remove empty lines                  // remove empty&comment lines
                   if(!*row_chars || *row_chars == '#')
                         continue;                          continue;
                 Array *row=new(pool) Array(pool);                  Array *row=new(pool) Array(pool);
                 while(char *cell_chars=lsplit(&row_chars, '\t')) {                  while(char *cell_chars=lsplit(&row_chars, '\t')) {
Line 133  static Table *fill_month_days(Request& r Line 134  static Table *fill_month_days(Request& r
         Pool& pool=r.pool();          Pool& pool=r.pool();
         Table *result=new(pool) Table(pool, &method_name, 0/*&columns*/);          Table *result=new(pool) Table(pool, &method_name, 0/*&columns*/);
   
     int year=params->as_int(1, r);      int year=params->as_int(1, "year must be int", r);
     int month=max(1, min(params->as_int(2, r), 12)) -1;      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};      tm tmIn={0, 0, 0, 1, month, year-1900};
     time_t t=mktime(&tmIn);      time_t t=mktime(&tmIn);
Line 176  static Table *fill_week_days(Request& r, Line 177  static Table *fill_week_days(Request& r,
         columns+=new(pool) String(pool, "weekday");          columns+=new(pool) String(pool, "weekday");
         Table *result=new(pool) Table(pool, &method_name, &columns);          Table *result=new(pool) Table(pool, &method_name, &columns);
   
     int year=params->as_int(1, r);      int year=params->as_int(1, "year must be int", r);
     int month=max(1, min(params->as_int(2, r), 12)) -1;      int month=max(1, min(params->as_int(2, "month must be int", r), 12)) -1;
     int day=params->as_int(3, r);      int day=params->as_int(3, "day must be int", r);
           
     tm tmIn={0, 0, 18, day, month, year-1900};      tm tmIn={0, 0, 18, day, month, year-1900};
     time_t t=mktime(&tmIn);      time_t t=mktime(&tmIn);
Line 320  static void _offset(Request& r, const St Line 321  static void _offset(Request& r, const St
 static void _menu(Request& r, const String& method_name, MethodParams *params) {  static void _menu(Request& r, const String& method_name, MethodParams *params) {
         Value& body_code=params->as_junction(0, "body must be code");          Value& body_code=params->as_junction(0, "body must be code");
                   
         Value *delim_code=params->size()==2?&params->get(1):0;          Value *delim_code=params->size()==2?&params->as_junction(1, "delim must be code"):0;
   
         VTable& vtable=*static_cast<VTable *>(r.self);          VTable& vtable=*static_cast<VTable *>(r.self);
         Table& table=vtable.table();          Table& table=vtable.table();
Line 470  static void _sort(Request& r, const Stri Line 471  static void _sort(Request& r, const Stri
         for(i=0; i<old_table.size(); i++)          for(i=0; i<old_table.size(); i++)
                 new_table+=seq[reverse?old_table.size()-1-i:i].row;                  new_table+=seq[reverse?old_table.size()-1-i:i].row;
   
         r.write_no_lang(*new(pool) VTable(pool, &new_table));          // replace any previous table value
           static_cast<VTable *>(r.self)->set_table(new_table);
 }  }
   
 static void _locate(Request& r, const String& method_name, MethodParams *params) {  static void _locate(Request& r, const String& method_name, MethodParams *params) {
Line 479  static void _locate(Request& r, const St Line 481  static void _locate(Request& r, const St
         VTable& vtable=*static_cast<VTable *>(r.self);          VTable& vtable=*static_cast<VTable *>(r.self);
         Table& table=vtable.table();          Table& table=vtable.table();
         Value& result=*new(pool) VBool(pool, table.locate(          Value& result=*new(pool) VBool(pool, table.locate(
                 params->get(0).as_string(),                   params->as_string(0, "column name must be string"),
                 params->get(1).as_string()));                  params->as_string(1, "value must be string")
           ));
         result.set_name(method_name);          result.set_name(method_name);
         r.write_no_lang(result);          r.write_no_lang(result);
 }  }

Removed from v.1.112  
changed lines
  Added in v.1.120


E-mail: