コード例 #1
0
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());
}
コード例 #2
0
void scKeys(CScriptVar *c, void *userdata) {
    IGNORE_PARAMETER(userdata);
    wString list = c->getParameter("obj")->trace2();
    list.CalcCount();
    //wString str = c->getParameter("this")->getString();
    //wString sep = c->getParameter("separator")->getString();
    CScriptVar *result = c->getReturnVar();
    result->setArray();
    int length = 0;
    
    for( int i = 0 ; i < list.Count() ; i++ ){
        result->setArrayIndex(length++, new CScriptVar(list.GetListString(i)));
    }
}
コード例 #3
0
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());
}
コード例 #4
0
void scStringSplit(CScriptVar *c, void *) {
    string str = c->getParameter("this")->getString();
    string sep = c->getParameter("separator")->getString();
    CScriptVar *result = c->getReturnVar();
    result->setArray();
    int length = 0;

    size_t pos = str.find(sep);
    while (pos != string::npos) {
      result->setArrayIndex(length++, new CScriptVar(str.substr(0,pos)));
      str = str.substr(pos+1);
      pos = str.find(sep);
    }

    if (str.size()>0)
      result->setArrayIndex(length++, new CScriptVar(str));
}
コード例 #5
0
void scStringSplit(CScriptVar *c, void *userdata) {
    IGNORE_PARAMETER(userdata);
    wString str = c->getParameter("this")->getString();
    wString sep = c->getParameter("separator")->getString();
    CScriptVar *result = c->getReturnVar();
    result->setArray();
    int length = 0;
    
    //consider sepatator length;
    int inc = sep.length();
    size_t pos = str.find(sep);
    while (pos != wString::npos) {
        result->setArrayIndex(length++, new CScriptVar(str.substr(0,pos)));
        str = str.substr(pos+inc);
        pos = str.find(sep);
    }
    
    if (str.size()>0)
    result->setArrayIndex(length++, new CScriptVar(str));
}
コード例 #6
0
//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);
}