|
|
| version 1.337, 2016/10/26 15:44:49 | version 1.342, 2017/02/07 22:00:30 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b table parser class. | Parser: @b table parser class. |
| Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 711 static void _csv_string(Request& r, Meth | Line 711 static void _csv_string(Request& r, Meth |
| table_to_csv(ost, table, control_chars, output_column_names); | table_to_csv(ost, table, control_chars, output_column_names); |
| r.write_no_lang(*new VString(*new String(pa_strdup(ost.str().c_str()), String::L_CLEAN))); | r.write(*new VString(*new String(pa_strdup(ost.str().c_str()), String::L_CLEAN))); |
| #else | #else |
| String sdata; | String sdata; |
| table_to_csv(sdata, table, control_chars, output_column_names); | table_to_csv(sdata, table, control_chars, output_column_names); |
| r.write_no_lang(*new VString(*new String(sdata.cstr(), String::L_CLEAN))); | r.write(*new VString(*new String(sdata.cstr(), String::L_CLEAN))); |
| #endif | #endif |
| } | } |
| Line 737 static void _count(Request& r, MethodPar | Line 737 static void _count(Request& r, MethodPar |
| } else | } else |
| result = table.count(); | result = table.count(); |
| r.write_no_lang(*new VInt(result)); | r.write(*new VInt(result)); |
| } | } |
| static void _line(Request& r, MethodParams&) { | static void _line(Request& r, MethodParams&) { |
| int result=1+GET_SELF(r, VTable).table().current(); | int result=1+GET_SELF(r, VTable).table().current(); |
| r.write_no_lang(*new VInt(result)); | r.write(*new VInt(result)); |
| } | } |
| static void _offset(Request& r, MethodParams& params) { | static void _offset(Request& r, MethodParams& params) { |
| Line 762 static void _offset(Request& r, MethodPa | Line 762 static void _offset(Request& r, MethodPa |
| int offset=params.as_int(params.count()-1, "offset must be expression", r); | int offset=params.as_int(params.count()-1, "offset must be expression", r); |
| table.offset(absolute, offset); | table.offset(absolute, offset); |
| } else | } else |
| r.write_no_lang(*new VInt(table.current())); | r.write(*new VInt(table.current())); |
| } | } |
| static void _menu(Request& r, MethodParams& params) { | static void _menu(Request& r, MethodParams& params) { |
| Line 781 static void _menu(Request& r, MethodPara | Line 781 static void _menu(Request& r, MethodPara |
| table.set_current(row); | table.set_current(row); |
| Value& 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); | TempSkip4Delimiter skip(r); |
| const String* s_processed=sv_processed.get_string(); | const String* s_processed=sv_processed.get_string(); |
| if(s_processed && !s_processed->is_empty()) { // we have body | if(s_processed && !s_processed->is_empty()) { // we have body |
| if(need_delim) // need delim & iteration produced string? | if(need_delim) // need delim & iteration produced string? |
| r.write_pass_lang(r.process(*delim_maybe_code)); | r.write(r.process(*delim_maybe_code)); |
| else | else |
| need_delim=true; | need_delim=true; |
| } | } |
| r.write_pass_lang(sv_processed); | r.write(sv_processed); |
| if(lskip==Request::SKIP_BREAK) | if(skip.check_break()) |
| break; | break; |
| } | } |
| } else { | } else { |
| Line 801 static void _menu(Request& r, MethodPara | Line 801 static void _menu(Request& r, MethodPara |
| table.set_current(row); | table.set_current(row); |
| r.process_write(body_code); | r.process_write(body_code); |
| Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); | |
| if(lskip==Request::SKIP_BREAK) | if(r.check_skip_break()) |
| break; | break; |
| } | } |
| } | } |
| Line 986 static void _hash(Request& r, MethodPara | Line 985 static void _hash(Request& r, MethodPara |
| throw Exception(PARSER_RUNTIME, 0, "value field(s) must be string or table or code"); | throw Exception(PARSER_RUNTIME, 0, "value field(s) must be string or table or code"); |
| } | } |
| if(value_type==C_STRING && value_fields.count()!=1) | if(value_type==C_STRING && value_fields.count()>1) |
| throw Exception(PARSER_RUNTIME, 0, "you can specify only one value field with option $.type[string]"); | throw Exception(PARSER_RUNTIME, 0, "you can't specify more then one value field with option $.type[string]"); |
| { | { |
| Value* key_param=¶ms[0]; | Value* key_param=¶ms[0]; |
| Line 1013 static void _hash(Request& r, MethodPara | Line 1012 static void _hash(Request& r, MethodPara |
| } | } |
| } | } |
| } | } |
| r.write_no_lang(result); | r.write(result); |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| Line 1044 static int sort_cmp_double(const void *a | Line 1043 static int sort_cmp_double(const void *a |
| static void _sort(Request& r, MethodParams& params) { | static void _sort(Request& r, MethodParams& params) { |
| Value& key_maker=params.as_junction(0, "key-maker must be code"); | Value& key_maker=params.as_junction(0, "key-maker must be code"); |
| bool reverse=params.count()>1/*..[desc|asc|]*/? | bool reverse=params.count()>1 /*..[desc|asc|]*/ && params.as_no_junction(1, "order must not be code").as_string()=="desc"; // default=asc |
| reverse=params.as_no_junction(1, "order must not be code").as_string()=="desc": | |
| false; // default=asc | |
| Table& old_table=GET_SELF(r, VTable).table(); | Table& old_table=GET_SELF(r, VTable).table(); |
| Table& new_table=*new Table(old_table.columns()); | Table& new_table=*new Table(old_table.columns()); |
| Line 1124 static void _locate(Request& r, MethodPa | Line 1121 static void _locate(Request& r, MethodPa |
| bool result=params[0].get_junction() || (params.count() == 1) ? | bool result=params[0].get_junction() || (params.count() == 1) ? |
| _locate_expression(table, r, params) : | _locate_expression(table, r, params) : |
| _locate_name_value(table, r, params); | _locate_name_value(table, r, params); |
| r.write_no_lang(VBool::get(result)); | r.write(VBool::get(result)); |
| } | } |
| Line 1142 static void _flip(Request& r, MethodPara | Line 1139 static void _flip(Request& r, MethodPara |
| new_table+=new_row; | new_table+=new_row; |
| } | } |
| r.write_no_lang(*new VTable(&new_table)); | r.write(*new VTable(&new_table)); |
| } | } |
| static void _foreach(Request& r, MethodParams& params) { | static void _foreach(Request& r, MethodParams& params) { |
| Line 1174 static void _foreach(Request& r, MethodP | Line 1171 static void _foreach(Request& r, MethodP |
| r.put_element(*var_context, *value_var_name, new VTable(&table)); | r.put_element(*var_context, *value_var_name, new VTable(&table)); |
| Value& 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); | TempSkip4Delimiter skip(r); |
| const String* s_processed=sv_processed.get_string(); | const String* s_processed=sv_processed.get_string(); |
| if(s_processed && !s_processed->is_empty()) { // we have body | if(s_processed && !s_processed->is_empty()) { // we have body |
| if(need_delim) // need delim & iteration produced string? | if(need_delim) // need delim & iteration produced string? |
| r.write_pass_lang(r.process(*delim_maybe_code)); | r.write(r.process(*delim_maybe_code)); |
| else | else |
| need_delim=true; | need_delim=true; |
| } | } |
| r.write_pass_lang(sv_processed); | r.write(sv_processed); |
| if(lskip==Request::SKIP_BREAK) | if(skip.check_break()) |
| break; | break; |
| } | } |
| } else { | } else { |
| Line 1199 static void _foreach(Request& r, MethodP | Line 1196 static void _foreach(Request& r, MethodP |
| r.put_element(*var_context, *value_var_name, new VTable(&table)); | r.put_element(*var_context, *value_var_name, new VTable(&table)); |
| r.process_write(body_code); | r.process_write(body_code); |
| Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); | |
| if(lskip==Request::SKIP_BREAK) | if(r.check_skip_break()) |
| break; | break; |
| } | } |
| } | } |
| Line 1448 static void _columns(Request& r, MethodP | Line 1444 static void _columns(Request& r, MethodP |
| } | } |
| } | } |
| r.write_no_lang(*new VTable(&result_table)); | r.write(*new VTable(&result_table)); |
| } | } |
| static void _select(Request& r, MethodParams& params) { | static void _select(Request& r, MethodParams& params) { |
| Line 1511 static void _select(Request& r, MethodPa | Line 1507 static void _select(Request& r, MethodPa |
| source_table.set_current(saved_current); | source_table.set_current(saved_current); |
| } | } |
| r.write_no_lang(*new VTable(&result_table)); | r.write(*new VTable(&result_table)); |
| } | } |
| // constructor | // constructor |