Diff for /parser3/src/classes/table.C between versions 1.326 and 1.334

version 1.326, 2016/09/08 20:41:47 version 1.334, 2016/09/29 18:49:43
Line 160  public: Line 160  public:
   
         String *extract(char *pos){          String *extract(char *pos){
                 String *result=new String;                  String *result=new String;
                 // first: their langs                  if(size_t len=strlen(pos)){
                 result->langs.append(result->body, langs, pos-base, strlen(pos));                          // first: their langs
                 // next: letters themselves                          result->langs.append(result->body, langs, pos-base, len);
                 result->body=Body(pos);                          // next: letters themselves
                           result->body=Body(pos);
                   }
                 return result;                  return result;
         }          }
 };  };
Line 171  public: Line 173  public:
 inline lsplit_sresult lsplit(char* *string_ref, const char* delims, StringSplitHelper& helper) {  inline lsplit_sresult lsplit(char* *string_ref, const char* delims, StringSplitHelper& helper) {
         lsplit_sresult result;          lsplit_sresult result;
         if(char *pos=*string_ref) {          if(char *pos=*string_ref) {
                 while(char* v=strpbrk(pos, delims)) {                  while(pos=strpbrk(pos, delims)) {
                         if(helper.check_lang(v)){                          if(helper.check_lang(pos)){
                                 result.delim=*v;                                  result.delim=*pos;
                                 *v=0;                                  *pos=0;
                                 result.piece=helper.extract(*string_ref);                                  result.piece=helper.extract(*string_ref);
                                 *string_ref=v+1;                                  *string_ref=pos+1;
                                 return result;                                  return result;
                         }                          }
                         pos=v+1;                          pos++;
                 }                  }
                 result.piece=helper.extract(*string_ref);                  result.piece=helper.extract(*string_ref);
                 *string_ref=0;                  *string_ref=0;
Line 196  static lsplit_sresult lsplit(char** stri Line 198  static lsplit_sresult lsplit(char** stri
   
                         // we are enclosed, searching for second encloser                          // we are enclosed, searching for second encloser
                         while(1) {                          while(1) {
                                 if(char* v=strchr(pos, encloser)){                                  if(pos=strchr(pos, encloser)){
                                         if(helper.check_lang(v)){                                          if(helper.check_lang(pos)){
                                                 *(v++)=0;                                                  *(pos++)=0;
                                                 result.append(helper.extract(*string_ref));                                                  result.append(helper.extract(*string_ref));
                                                 if(*v==encloser && helper.check_lang(v)){ // double-encloser stands for encloser                                                  if(*pos==encloser && helper.check_lang(pos)){ // double-encloser stands for encloser
                                                         *string_ref=v+1;                                                          *string_ref=pos;
                                                 } else {                                                  } else {
                                                         *string_ref=pos=v;                                                          *string_ref=pos;
                                                         break;                                                          break;
                                                 }                                                  }
                                         }                                          }
                                         pos=v+1;                                          pos++;
                                 }{                                  } else {
                                         result.append(helper.extract(*string_ref));                                          result.append(helper.extract(*string_ref));
                                         *string_ref=0;                                          *string_ref=0;
                                         return result;                                          return result;
Line 216  static lsplit_sresult lsplit(char** stri Line 218  static lsplit_sresult lsplit(char** stri
                         }                          }
   
                         // we are no longer enclosed, searching for delimiter                          // we are no longer enclosed, searching for delimiter
                         while(char* v=strpbrk(pos, delims)) {                          while(pos=strpbrk(pos, delims)) {
                                 if(helper.check_lang(v)){                                  if(helper.check_lang(pos)){
                                         result.delim=*v;                                          result.delim=*pos;
                                         if(v>*string_ref){                                          if(pos>*string_ref){
                                                 *v=0;                                                  *pos=0;
                                                 result.append(helper.extract(*string_ref));                                                  result.append(helper.extract(*string_ref));
                                         }                                          }
                                         *string_ref=v+1;                                          *string_ref=pos+1;
                                         return result;                                          return result;
                                 }                                  }
                                 pos=v+1;                                  pos++;
                         }                          }
                         result.append(helper.extract(*string_ref));                          result.append(helper.extract(*string_ref));
                         *string_ref=0;                          *string_ref=0;
Line 362  static lsplit_result lsplit(char** strin Line 364  static lsplit_result lsplit(char** strin
                                 *write++=c;                                  *write++=c;
                         }                          }
   
                         // we are no longer enclosed, searching for delimiter, skipping extra enclosers                          // we are no longer enclosed, searching for delimiter
                         while(c=*read++) {                          while(c=*read++) {
                                 if(c==delims[0] || c==delims[1]) {                                  if(c==delims[0] || c==delims[1]) {
                                         result.delim=c;                                          result.delim=c;
                                         break;                                          break;
                                 } else  if(c!=encloser)                                  } else 
                                         *write++=c;                                          *write++=c;
                         }                          }
   
Line 779  static void _menu(Request& r, MethodPara Line 781  static void _menu(Request& r, MethodPara
                 for(size_t row=0; row<table.count(); row++) {                  for(size_t row=0; row<table.count(); row++) {
                         table.set_current(row);                          table.set_current(row);
   
                         StringOrValue sv_processed=r.process(body_code);                          Value& sv_processed=r.process(body_code);
                         Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);                          Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);
   
                         const String* s_processed=sv_processed.get_string();                          const String* s_processed=sv_processed.get_string();
Line 827  static void table_row_to_hash(Table::ele Line 829  static void table_row_to_hash(Table::ele
         const String* key;          const String* key;
         if(info->key_code) {          if(info->key_code) {
                 info->table->set_current(info->row++); // change context row                  info->table->set_current(info->row++); // change context row
                 StringOrValue sv_processed=info->r->process(*info->key_code);                  Value& sv_processed=info->r->process(*info->key_code);
                 key=&sv_processed.as_string();                  key=&sv_processed.as_string();
         } else {          } else {
                 key=info->key_field<row->count()?row->get(info->key_field):0;                  key=info->key_field<row->count()?row->get(info->key_field):0;
Line 882  static void table_row_to_hash(Table::ele Line 884  static void table_row_to_hash(Table::ele
                 case C_CODE: {                  case C_CODE: {
                         if(!info->key_code)                          if(!info->key_code)
                                 info->table->set_current(info->row++); // change context row                                  info->table->set_current(info->row++); // change context row
                         exist=info->hash->put_dont_replace(*key, &info->r->process(*info->value_code).as_value());                          exist=info->hash->put_dont_replace(*key, &info->r->process(*info->value_code));
                         break;                          break;
                 }                  }
         }          }
Line 1074  static void _sort(Request& r, MethodPara Line 1076  static void _sort(Request& r, MethodPara
         if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) {          if(r.charsets.source().NAME()=="KOI8-R" && key_values_are_strings) {
                 for(i=0; i<old_count; i++)                  for(i=0; i<old_count; i++)
                         if(*seq[i].value.c_str)                          if(*seq[i].value.c_str)
                                 seq[i].value.c_str=Charset::transcode(seq[i].value.c_str, r.charsets.source(), UTF8_charset).cstr();                                  seq[i].value.c_str=Charset::transcode(seq[i].value.c_str, r.charsets.source(), pa_UTF8_charset).cstr();
         }          }
   
         // sort keys          // sort keys
Line 1147  static void _flip(Request& r, MethodPara Line 1149  static void _flip(Request& r, MethodPara
 static void _foreach(Request& r, MethodParams& params) {  static void _foreach(Request& r, MethodParams& params) {
         InCycle temp(r);          InCycle temp(r);
   
         const String& rownum_name=params.as_string(0, "rownum-var name must be string");          const String* rownum_var_name=&params.as_string(0, "rownum-var name must be string");
         const String& value_name=params.as_string(1, "value-var name must be string");          const String* value_var_name=&params.as_string(1, "value-var name must be string");
   
         Value& body_code=params.as_junction(2, "body must be code");          Value& body_code=params.as_junction(2, "body must be code");
                   
Line 1157  static void _foreach(Request& r, MethodP Line 1159  static void _foreach(Request& r, MethodP
         Table& table=GET_SELF(r, VTable).table();          Table& table=GET_SELF(r, VTable).table();
         size_t saved_current=table.current();          size_t saved_current=table.current();
   
         const String* rownum_var_name=rownum_name.is_empty()? 0 : &rownum_name;          rownum_var_name=rownum_var_name->is_empty()? 0 : rownum_var_name;
         const String* value_var_name=value_name.is_empty()? 0 : &value_name;          value_var_name=value_var_name->is_empty()? 0 : value_var_name;
   
         Value* var_context=r.get_method_frame()->caller();          Value* var_context=r.get_method_frame()->caller();
   
Line 1172  static void _foreach(Request& r, MethodP Line 1174  static void _foreach(Request& r, MethodP
                         if(value_var_name)                          if(value_var_name)
                                 r.put_element(*var_context, *value_var_name, new VTable(&table));                                  r.put_element(*var_context, *value_var_name, new VTable(&table));
   
                         StringOrValue sv_processed=r.process(body_code);                          Value& sv_processed=r.process(body_code);
                         Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);                          Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING);
   
                         const String* s_processed=sv_processed.get_string();                          const String* s_processed=sv_processed.get_string();

Removed from v.1.326  
changed lines
  Added in v.1.334


E-mail: