--- parser3/src/classes/string.C 2007/08/20 10:02:51 1.154 +++ parser3/src/classes/string.C 2007/11/27 10:51:01 1.158 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_STRING_C="$Date: 2007/08/20 10:02:51 $"; +static const char * const IDENT_STRING_C="$Date: 2007/11/27 10:51:01 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -96,7 +96,19 @@ static void _bool(Request& r, MethodPara throw Exception(PARSER_RUNTIME, 0, "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 if(params.count()>0) converted=params.as_bool(0, "default must be bool", r); // (default) @@ -219,9 +231,9 @@ static int split_options(const String* o 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); - *columns+=new String("piece"); + *columns+=column_name; Table& table=*new Table(columns, pieces.count()); if(right) { // right @@ -274,8 +286,19 @@ static void split_with_options(Request& bool right=(bits & SPLIT_RIGHT) != 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)); } @@ -524,7 +547,7 @@ static void _sql(Request& r, MethodParam static void _replace(Request& r, MethodParams& params) { 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) throw Exception(PARSER_RUNTIME, 0, @@ -596,7 +619,7 @@ static void _append(Request& r, MethodPa // c=a+b VString& va=GET_SELF(r, VString); 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); c.append(b, String::L_PASS_APPENDED); va.set_string(c); @@ -605,7 +628,7 @@ static void _append(Request& r, MethodPa static void _base64(Request& r, MethodParams& params) { if(params.count()) { // 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; size_t decoded_size=0; pa_base64_decode(cstr, strlen(cstr), decoded_cstr, decoded_size); @@ -651,7 +674,8 @@ MString::MString(): Methoded("string") { // ^string.split[delim] // ^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 // ^string.lsplit[delim] add_native_method("lsplit", Method::CT_DYNAMIC, _lsplit, 1, 1);