Esempio n. 1
0
//---------------------------------------------------------------------------
// TJSGetExceptionObject : retrieves TJS 'Exception' object
//---------------------------------------------------------------------------
void TJSGetExceptionObject(tTJS *tjs, tTJSVariant *res, tTJSVariant &msg,
	tTJSVariant *trace/* trace is optional */)
{
	if(!res) return; // not prcess

	// retrieve class "Exception" from global
	iTJSDispatch2 *global = tjs->GetGlobalNoAddRef();
	tTJSVariant val;
	static tTJSString Exception_name(TJS_W("Exception"));
	tjs_error hr = global->PropGet(0, Exception_name.c_str(),
		Exception_name.GetHint(), &val, global);
	if(TJS_FAILED(hr)) TJS_eTJSError(TJSExceptionNotFound);
	// create an Exception object
	iTJSDispatch2 *excpobj;
	tTJSVariantClosure clo = val.AsObjectClosureNoAddRef();
	tTJSVariant *pmsg = &msg;
	hr = clo.CreateNew(0, NULL, NULL, &excpobj, 1, &pmsg, clo.ObjThis);
	if(TJS_FAILED(hr)) TJS_eTJSError(TJSExceptionNotFound);
	if(trace)
	{
		static tTJSString trace_name(TJS_W("trace"));
		excpobj->PropSet(TJS_MEMBERENSURE, trace_name.c_str(), trace_name.GetHint(),
			trace, excpobj);
	}
	*res = tTJSVariant(excpobj, excpobj);
	excpobj->Release();
}
Esempio n. 2
0
//---------------------------------------------------------------------------
void tTJSString::Replace(const tTJSString &from, const tTJSString &to, bool forall)
{
	// replaces the string partial "from", to "to".
	// all "from" are replaced when "forall" is true.
	if(IsEmpty()) return;
	if(from.IsEmpty()) return;

	tjs_int fromlen = from.GetLen();

	for(;;)
	{
		const tjs_char *st;
		const tjs_char *p;
		st = c_str();
		p = TJS_strstr(st, from.c_str());
		if(p)
		{
			tTJSString name(*this, p-st);
			tTJSString n2(p + fromlen);
			*this = name + to + n2;
			if(!forall) break;
		}
		else
		{
			break;
		}
	}
}