--- parser3/src/classes/string.C 2015/10/08 23:14:56 1.221 +++ parser3/src/classes/string.C 2016/05/18 17:47:22 1.225 @@ -1,7 +1,7 @@ /** @file Parser: @b string parser class. - Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -20,7 +20,7 @@ #include "pa_vregex.h" #include "pa_charsets.h" -volatile const char * IDENT_STRING_C="$Id: string.C,v 1.221 2015/10/08 23:14:56 moko Exp $"; +volatile const char * IDENT_STRING_C="$Id: string.C,v 1.225 2016/05/18 17:47:22 moko Exp $"; // class @@ -31,7 +31,7 @@ public: // global variable -DECLARE_CLASS_VAR(string, new MString, 0); +DECLARE_CLASS_VAR(string, new MString); // void class, inherited from string and thus should be inited afterwards @@ -42,7 +42,7 @@ public: // void global variable should be after string global variable -DECLARE_CLASS_VAR(void, new MVoid, 0); +DECLARE_CLASS_VAR(void, new MVoid); // defines for statics @@ -92,25 +92,22 @@ static void _int(Request& r, MethodParam static void _double(Request& r, MethodParams& params) { const String& self_string=GET_SELF(r, VString).string(); - double converted; if(self_string.is_empty()) { if(params.count()>0) - converted=params.as_double(0, "default must be double", r); // (default) + r.write_no_lang(*new VDouble(params.as_double(0, "default must be double", r))); // (default) else throw Exception(PARSER_RUNTIME, 0, "unable to convert empty string without default specified"); } else { try { - converted=self_string.as_double(); + r.write_no_lang(*new VDouble(self_string.as_double())); } catch(...) { // convert problem if(params.count()>0) - converted=params.as_double(0, "default must be double", r); // (default) + r.write_no_lang(*new VDouble(params.as_double(0, "default must be double", r))); // (default) else rethrow; // we have a problem when no default } } - - r.write_no_lang(*new VDouble(converted)); } static void _bool(Request& r, MethodParams& params) { @@ -795,6 +792,13 @@ static void _unescape(Request& r, Method } } +static void _contains(Request& r, MethodParams& params) { + // empty or whitespace string is hash compatible + GET_SELF(r, VString).get_element(params.as_string(0, "key must be string")); + // ignoring result as it allways null + r.write_no_lang(VBool::get(false)); +} + // constructor MString::MString(): Methoded("string") { @@ -880,4 +884,7 @@ MString::MString(): Methoded("string") { // ^string:unescape[js|uri;escaped;$.charset[...]] add_native_method("unescape", Method::CT_STATIC, _unescape, 2, 3); + + // ^string.contains[key] for hash compatibility + add_native_method("contains", Method::CT_DYNAMIC, _contains, 1, 1); }