Added support for (un)hexify functions: btoh and htob.
git-svn-id: http://yate.null.ro/svn/yate/trunk@5865 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
05a21a1d34
commit
99f1280a37
|
@ -246,6 +246,8 @@ public:
|
|||
params().addParam(new ExpFunction("btoa"));
|
||||
params().addParam(new ExpFunction("atoh"));
|
||||
params().addParam(new ExpFunction("htoa"));
|
||||
params().addParam(new ExpFunction("btoh"));
|
||||
params().addParam(new ExpFunction("htob"));
|
||||
}
|
||||
static void initialize(ScriptContext* context);
|
||||
inline void resetWorker()
|
||||
|
@ -1091,6 +1093,39 @@ bool JsEngine::runNative(ObjList& stack, const ExpOperation& oper, GenObject* co
|
|||
else
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(false));
|
||||
}
|
||||
else if (oper.name() == YSTRING("btoh")) {
|
||||
// hex_str = Engine.btoh(str[,sep[,upCase]])
|
||||
ObjList args;
|
||||
ExpOperation* data = 0;
|
||||
ExpOperation* sep = 0;
|
||||
ExpOperation* upCase = 0;
|
||||
if (!extractStackArgs(1,this,stack,oper,context,args,&data,&sep,&upCase))
|
||||
return false;
|
||||
String tmp;
|
||||
tmp.hexify((void*)data->c_str(),data->length(),(sep ? sep->at(0) : 0),
|
||||
(upCase && upCase->toBoolean()));
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(tmp,"hex"));
|
||||
}
|
||||
else if (oper.name() == YSTRING("htob")) {
|
||||
// str = Engine.unHexify(hex_str[,sep])
|
||||
ObjList args;
|
||||
ExpOperation* data = 0;
|
||||
ExpOperation* sep = 0;
|
||||
if (!extractStackArgs(1,this,stack,oper,context,args,&data,&sep))
|
||||
return false;
|
||||
bool ok = true;
|
||||
DataBlock buf;
|
||||
if (!sep)
|
||||
ok = buf.unHexify(data->c_str(),data->length());
|
||||
else
|
||||
ok = buf.unHexify(data->c_str(),data->length(),sep->at(0));
|
||||
if (ok) {
|
||||
String tmp((const char*)buf.data(),buf.length());
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(tmp,"bin"));
|
||||
}
|
||||
else
|
||||
ExpEvaluator::pushOne(stack,new ExpOperation(false));
|
||||
}
|
||||
else
|
||||
return JsObject::runNative(stack,oper,context);
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue