//PregReplace void scPregStringReplace(CScriptVar *c, void *userdata) { IGNORE_PARAMETER(userdata); wString result; wString str = c->getParameter("this")->getString(); CScriptVar *arrp = c->getParameter("pattern"); vector<wString> patterns; vector<wString> replaces; int pn = arrp->getArrayLength(); int rn; if( pn ){ CScriptVar *arrr = c->getParameter("replace"); rn = arrr->getArrayLength(); if( pn == rn ){ for (int i=0;i<pn;i++) { patterns.push_back(arrp->getArrayIndex(i)->getString()); replaces.push_back(arrr->getArrayIndex(i)->getString()); } } }else{ wString pattern = c->getParameter("pattern")->getString(); wString replace = c->getParameter("replace")->getString(); patterns.push_back(pattern); replaces.push_back(replace); } dregex::replace(&result, str, patterns, replaces); c->getReturnVar()->setString(result); }
void scArrayJoin(CScriptVar *c, void *data) { string sep = c->getParameter("separator")->getString(); CScriptVar *arr = c->getParameter("this"); ostringstream sstr; int l = arr->getArrayLength(); for (int i=0;i<l;i++) { if (i>0) sstr << sep; sstr << arr->getArrayIndex(i)->getString(); } c->getReturnVar()->setString(sstr.str()); }
void scArrayJoin(CScriptVar *c, void *userdata) { IGNORE_PARAMETER(userdata); wString sep = c->getParameter("separator")->getString(); CScriptVar *arr = c->getParameter("this"); wString sstr; int l = arr->getArrayLength(); for (int i=0;i<l;i++) { if (i>0){ sstr += sep; } sstr += arr->getArrayIndex(i)->getString(); } c->getReturnVar()->setString(sstr.c_str()); }