--- parser3/src/classes/string.C 2019/11/20 20:48:25 1.243 +++ parser3/src/classes/string.C 2020/12/17 20:01:03 1.249 @@ -1,7 +1,7 @@ /** @file Parser: @b string parser class. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -21,7 +21,7 @@ #include "pa_vregex.h" #include "pa_charsets.h" -volatile const char * IDENT_STRING_C="$Id: string.C,v 1.243 2019/11/20 20:48:25 moko Exp $"; +volatile const char * IDENT_STRING_C="$Id: string.C,v 1.249 2020/12/17 20:01:03 moko Exp $"; // class @@ -153,15 +153,15 @@ static void _bool(Request& r, MethodPara } static void _left(Request& r, MethodParams& params) { - ssize_t sn=params.as_int(0, "n must be int", r); + int sn=params.as_int(0, "n must be int", r); const String& string=GET_SELF(r, VString).string(); - r.write(sn<0 ? string : string.mid(r.charsets.source(), 0, (size_t)sn)); + r.write(sn<0 ? string : string.mid(r.charsets.source(), 0, sn)); } static void _right(Request& r, MethodParams& params) { - ssize_t sn=params.as_int(0, "n must be int", r); + int sn=params.as_int(0, "n must be int", r); if(sn>0){ - size_t n=(size_t)sn; + size_t n=sn; const String& string=GET_SELF(r, VString).string(); size_t length=string.length(r.charsets.source()); r.write(n=0", sbegin); - size_t begin=(size_t)sbegin; + int begin=params.as_int(0, "p must be int", r); + if(begin<0) + throw Exception(PARSER_RUNTIME, 0, "p(%d) must be >=0", begin); size_t end; size_t length=0; + if(params.count()>1) { - ssize_t sn=params.as_int(1, "n must be int", r); - if(sn<0) - throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", sn); - end=begin+(size_t)sn; + int n=params.as_int(1, "n must be int", r); + if(n<0) + throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", n); + end=begin+n; } else { length=string.length(r.charsets.source()); end=length; @@ -195,18 +195,17 @@ static void _pos(Request& r, MethodParam Value& substr=params.as_no_junction(0, "substr must not be code"); const String& string=GET_SELF(r, VString).string(); - ssize_t offset=0; + int offset=0; if(params.count()>1){ offset=params.as_int(1, "n must be int", r); if(offset<0) throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", offset); } - r.write(*new VInt((int)string.pos(r.charsets.source(), substr.as_string(), (size_t)offset))); + r.write(*new VInt((int)string.pos(r.charsets.source(), substr.as_string(), offset))); } -static void split_list(MethodParams& params, int paramIndex, const String& string, ArrayString& result) { - Value& delim_value=params.as_no_junction(paramIndex, "delimiter must not be code"); +static void split_list(Value& delim_value, const String& string, ArrayString& result) { string.split(result, 0, delim_value.as_string()); } @@ -286,7 +285,7 @@ static void split_with_options(Request& size_t params_count=params.count(); ArrayString pieces; - split_list(params, 0, string, pieces); + split_list(params.as_no_junction(0, "delimiter must not be code"), string, pieces); if(!bits) { const String* options=0; @@ -553,9 +552,11 @@ static void _replace(Request& r, MethodP if(params.count()==1) { // ^string.replace[table] - Table* table=params.as_table(0, "param"); - Dictionary dict(*table); - r.write(src.replace(dict)); + if(Table* table=params.as_table(0, "param")){ + Dictionary dict(*table); + r.write(src.replace(dict)); + } else + r.write(src); } else { // ^string.replace[from-string;to-string] Dictionary dict(params.as_string(0, "from must be string"), params.as_string(1, "to must be string")); @@ -602,7 +603,7 @@ static void _save(Request& r, MethodPara String::Body sbody=src.cstr_to_string_body_untaint(String::L_AS_IS, r.connection(false), &r.charsets); // write - file_write(r.charsets, r.absolute(file_name), sbody.cstr(), sbody.length(), true, do_append, asked_charset); + file_write(r.charsets, r.full_disk_path(file_name), sbody.cstr(), sbody.length(), true, do_append, asked_charset); } static void _normalize(Request& r, MethodParams&) {