--- parser3/src/classes/string.C 2016/03/31 21:46:20 1.224 +++ parser3/src/classes/string.C 2016/09/21 15:35:10 1.229 @@ -20,7 +20,7 @@ #include "pa_vregex.h" #include "pa_charsets.h" -volatile const char * IDENT_STRING_C="$Id: string.C,v 1.224 2016/03/31 21:46:20 moko Exp $"; +volatile const char * IDENT_STRING_C="$Id: string.C,v 1.229 2016/09/21 15:35:10 moko Exp $"; // class @@ -202,21 +202,15 @@ static void _pos(Request& r, MethodParam 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); + throw Exception(PARSER_RUNTIME, 0, "n(%d) must be >=0", offset); } r.write_no_lang(*new VInt((int)string.pos(r.charsets.source(), substr.as_string(), (size_t)offset))); } -static void split_list(MethodParams& params, int paramIndex, - const String& string, - ArrayString& result) { +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"); - - size_t pos_after=0; - string.split(result, pos_after, delim_value.as_string()); + string.split(result, 0, delim_value.as_string()); } #define SPLIT_LEFT 0x0001 @@ -626,7 +620,7 @@ static void _save(Request& r, MethodPara // ^file.save[filespec;$.charset[] $.append(true)] int valid_options=0; if(Value* vcharset_name=options->get(PA_CHARSET_NAME)){ - asked_charset=&::charsets.get(vcharset_name->as_string().change_case(r.charsets.source(), String::CC_UPPER)); + asked_charset=&pa_charsets.get(vcharset_name->as_string()); valid_options++; } if(Value* vappend=options->get(MODE_APPEND)){ @@ -769,7 +763,7 @@ static void _unescape(Request& r, Method if(HashStringValue* options=params.as_hash(2)) { int valid_options=0; if(Value* vcharset_name=options->get(PA_CHARSET_NAME)){ - from_charset=&::charsets.get(vcharset_name->as_string().change_case(r.charsets.source(), String::CC_UPPER)); + from_charset=&pa_charsets.get(vcharset_name->as_string()); valid_options++; } if(valid_options!=options->count()) @@ -782,7 +776,7 @@ static void _unescape(Request& r, Method } else if(mode==UNESCAPE_MODE_URI){ mode_js=false; } else { - throw Exception(PARSER_RUNTIME, &mode, "is invalid mode, must be either '"UNESCAPE_MODE_JS"' or '"UNESCAPE_MODE_URI"'"); + throw Exception(PARSER_RUNTIME, &mode, "is invalid mode, must be either '" UNESCAPE_MODE_JS "' or '" UNESCAPE_MODE_URI "'"); } const char* unescaped=unescape_chars(src.cstr(), src.length(), from_charset, mode_js); @@ -792,6 +786,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") { @@ -877,4 +878,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); }