|
|
| version 1.154, 2007/08/20 10:02:51 | version 1.161, 2008/07/03 09:17:57 |
|---|---|
| Line 96 static void _bool(Request& r, MethodPara | Line 96 static void _bool(Request& r, MethodPara |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "parameter is empty string, error converting"); | "parameter is empty string, error converting"); |
| converted=self_string.as_bool(); | |
| try { | |
| converted=self_string.as_bool(); | |
| } catch(...) { | |
| const String& lower_string=self_string.change_case(r.charsets.source(), String::CC_LOWER); | |
| if(lower_string == "true"){ | |
| converted=true; | |
| } else if (lower_string == "false"){ | |
| converted=false; | |
| } else { | |
| rethrow; | |
| } | |
| } | |
| } catch(...) { // convert problem | } catch(...) { // convert problem |
| if(params.count()>0) | if(params.count()>0) |
| converted=params.as_bool(0, "default must be bool", r); // (default) | converted=params.as_bool(0, "default must be bool", r); // (default) |
| Line 113 static void _bool(Request& r, MethodPara | Line 125 static void _bool(Request& r, MethodPara |
| // for some time due to stupid {} in original design | // for some time due to stupid {} in original design |
| const String& fmt=r.process_to_string(fmt_maybe_code); | const String& fmt=r.process_to_string(fmt_maybe_code); |
| const char* buf=format(r.get_self().as_double(), fmt.cstrm()); | const char* buf=format(r.get_self().as_double(), fmt.trim().cstrm()); |
| r.write_no_lang(String(buf)); | r.write_no_lang(String(buf)); |
| } | } |
| Line 137 static void _right(Request& r, MethodPar | Line 149 static void _right(Request& r, MethodPar |
| 0, | 0, |
| "n(%d) must be >=0", sn); | "n(%d) must be >=0", sn); |
| size_t n=(size_t)sn; | size_t n=(size_t)sn; |
| const String& string=GET_SELF(r, VString).string(); | const String& string=GET_SELF(r, VString).string(); |
| size_t length=string.length(); | size_t length=string.length(); |
| r.write_assign_lang(n<length?string.mid(length-n, string.length()):string); | r.write_assign_lang(n<length?string.mid(length-n, string.length()):string); |
| Line 219 static int split_options(const String* o | Line 230 static int split_options(const String* o |
| return result; | return result; |
| } | } |
| static Table& split_vertical(ArrayString& pieces, bool right) { | static Table& split_vertical(ArrayString& pieces, bool right, const String* column_name) { |
| Table::columns_type columns(new ArrayString); | Table::columns_type columns(new ArrayString); |
| *columns+=new String("piece"); | *columns+=column_name; |
| Table& table=*new Table(columns, pieces.count()); | Table& table=*new Table(columns, pieces.count()); |
| if(right) { // right | if(right) { // right |
| Line 274 static void split_with_options(Request& | Line 285 static void split_with_options(Request& |
| bool right=(bits & SPLIT_RIGHT) != 0; | bool right=(bits & SPLIT_RIGHT) != 0; |
| bool horizontal=(bits & SPLIT_HORIZONTAL) !=0; | bool horizontal=(bits & SPLIT_HORIZONTAL) !=0; |
| Table& table=horizontal?split_horizontal(pieces, right) | |
| :split_vertical(pieces, right); | const String* column_name=0; |
| if(params.count()>2){ | |
| column_name=¶ms.as_string(2, COLUMN_NAME_MUST_BE_STRING); | |
| if (horizontal && column_name->length()) | |
| throw Exception(PARSER_RUNTIME, | |
| column_name, | |
| "column name can't be specified with horisontal split"); | |
| } | |
| if(!column_name || !column_name->length()) | |
| column_name=new String("piece"); | |
| Table& table=horizontal?split_horizontal(pieces, right):split_vertical(pieces, right, column_name); | |
| r.write_no_lang(*new VTable(&table)); | r.write_no_lang(*new VTable(&table)); |
| } | } |
| Line 344 static void _match(Request& r, MethodPar | Line 366 static void _match(Request& r, MethodPar |
| matches_count); | matches_count); |
| // r.write_assign_lang(*new VTable(table)); | // r.write_assign_lang(*new VTable(table)); |
| if(table){ | if(table){ |
| r.write_assign_lang(*new VTable(table)); | r.write_assign_lang(*new VTable(table)); |
| } else { | } else { |
| r.write_assign_lang(*new VInt(matches_count)); | r.write_assign_lang(*new VInt(matches_count)); |
| } | } |
| Line 444 const String* sql_result_string(Request& | Line 466 const String* sql_result_string(Request& |
| Value& statement=params.as_junction(0, "statement must be code"); | Value& statement=params.as_junction(0, "statement must be code"); |
| HashStringValue* bind=0; | HashStringValue* bind=0; |
| ulong limit=0; | ulong limit=SQL_NO_LIMIT; |
| ulong offset=0; | ulong offset=0; |
| default_code=0; | default_code=0; |
| if(params.count()>1) { | if(params.count()>1) { |
| Line 488 const String* sql_result_string(Request& | Line 510 const String* sql_result_string(Request& |
| const char* statement_cstr= | const char* statement_cstr= |
| statement_string.cstr(String::L_UNSPECIFIED, r.connection()); | statement_string.cstr(String::L_UNSPECIFIED, r.connection()); |
| String_sql_event_handlers handlers(statement_string, statement_cstr); | String_sql_event_handlers handlers(statement_string, statement_cstr); |
| r.connection()->query( | r.connection()->query( |
| statement_cstr, | statement_cstr, |
| placeholders_count, placeholders, | placeholders_count, placeholders, |
| Line 524 static void _sql(Request& r, MethodParam | Line 547 static void _sql(Request& r, MethodParam |
| static void _replace(Request& r, MethodParams& params) { | static void _replace(Request& r, MethodParams& params) { |
| const String& src=GET_SELF(r, VString).string(); | const String& src=GET_SELF(r, VString).string(); |
| Table* table=params.as_no_junction(0, "parameter must not be code").get_table(); | Table* table=params.as_no_junction(0, PARAM_MUST_NOT_BE_CODE).get_table(); |
| if(!table) | if(!table) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| Line 596 static void _append(Request& r, MethodPa | Line 619 static void _append(Request& r, MethodPa |
| // c=a+b | // c=a+b |
| VString& va=GET_SELF(r, VString); | VString& va=GET_SELF(r, VString); |
| const String& a=va.string(); | const String& a=va.string(); |
| const String& b=params.as_string(0, "parameter must be string"); | const String& b=params.as_string(0, PARAMETER_MUST_BE_STRING); |
| String& c=*new String(a); | String& c=*new String(a); |
| c.append(b, String::L_PASS_APPENDED); | c.append(b, String::L_PASS_APPENDED); |
| va.set_string(c); | va.set_string(c); |
| Line 605 static void _append(Request& r, MethodPa | Line 628 static void _append(Request& r, MethodPa |
| static void _base64(Request& r, MethodParams& params) { | static void _base64(Request& r, MethodParams& params) { |
| if(params.count()) { | if(params.count()) { |
| // decode | // decode |
| const char* cstr=params.as_string(0, "parameter must be string").cstr(); | const char* cstr=params.as_string(0, PARAMETER_MUST_BE_STRING).cstr(); |
| char* decoded_cstr=0; | char* decoded_cstr=0; |
| size_t decoded_size=0; | size_t decoded_size=0; |
| pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size); | pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size); |
| Line 651 MString::MString(): Methoded("string") { | Line 674 MString::MString(): Methoded("string") { |
| // ^string.split[delim] | // ^string.split[delim] |
| // ^string.split[delim][options] | // ^string.split[delim][options] |
| add_native_method("split", Method::CT_DYNAMIC, _split, 1, 2); | // ^string.split[delim][options][column name] |
| add_native_method("split", Method::CT_DYNAMIC, _split, 1, 3); | |
| // old names for backward compatibility | // old names for backward compatibility |
| // ^string.lsplit[delim] | // ^string.lsplit[delim] |
| add_native_method("lsplit", Method::CT_DYNAMIC, _lsplit, 1, 1); | add_native_method("lsplit", Method::CT_DYNAMIC, _lsplit, 1, 1); |