• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ JSStringGetUTF8CString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中JSStringGetUTF8CString函数的典型用法代码示例。如果您正苦于以下问题:C++ JSStringGetUTF8CString函数的具体用法?C++ JSStringGetUTF8CString怎么用?C++ JSStringGetUTF8CString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了JSStringGetUTF8CString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: JSValueToStringCopy

bool S_CCLabelTTF::initWithContext(JSContextRef ctx, JSObjectRef obj, size_t argumentCount, const JSValueRef arguments[])
{
	bool result = true;
	if (argumentCount == 3) {
		char *buffText = (char *)malloc(128);
		char *buffFont = (char *)malloc(128);
		
		JSStringRef jsLabelText = JSValueToStringCopy(ctx, arguments[0], NULL);
		JSStringRef jsFontName  = JSValueToStringCopy(ctx, arguments[1], NULL);
		float fontSize = JSValueToNumber(ctx, arguments[2], NULL);
		
		JSStringGetUTF8CString(jsLabelText, buffText, 128);
		JSStringGetUTF8CString(jsFontName, buffFont, 128);
		
		if (!CCLabelTTF::initWithString(buffText, buffFont, fontSize)) {
			return false;
		}
		free(buffText);
		free(buffFont);
	} else {
		if (!CCLabelTTF::init()) {
			result = false;
		}
	}
	if (result) {
		setUserData(obj);
	}
	return result;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:29,代码来源:S_CCLabel.cpp


示例2: jsstring_to_cstr

char* jsstring_to_cstr(JSContextRef ctx, JSStringRef js_string)
{
  size_t len = JSStringGetMaximumUTF8CStringSize(js_string);
  char *c_str = g_new(char, len);
  JSStringGetUTF8CString(js_string, c_str, len);
  return c_str;
}
开发者ID:electricface,项目名称:dde,代码行数:7,代码来源:jsextension.c


示例3: spjsdata_has_property_cb

// has property methods for callbacks. method parameter definitions( e.message, e.otp, e.data)
bool spjsdata_has_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
    bool ret = false;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char *)malloc(propertySize * sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
 	if(strcmp(kParamOTP,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamCode,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamMessage,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamData,property) == 0)
    {
        ret = true;
    }
    
    free(property);
    return ret;
}
开发者ID:memedum90,项目名称:demoforios,代码行数:27,代码来源:SPJSDPPlugin.cpp


示例4: setMarkedTextCallback

static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    if (!view)
        return JSValueMakeUndefined(context);

    if (argumentCount < 3)
        return JSValueMakeUndefined(context);

    JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string);
    GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
    JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize);
    JSStringRelease(string);

    int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    int end = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, end);

    return JSValueMakeUndefined(context);
}
开发者ID:wufuyue,项目名称:TCL_S820,代码行数:27,代码来源:TextInputController.cpp


示例5: web_view_javascript_finished

static void web_view_javascript_finished(GObject      *object,
                              GAsyncResult *result,
                              gpointer      user_data)
{
    WebKitJavascriptResult *js_result;
    JSValueRef              value;
    JSGlobalContextRef      context;
    GError                 *error = NULL;

    js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error);
    if (!js_result) {
        g_warning ("Error running javascript: %s", error->message);
        g_error_free (error);
        return;
    }

    context = webkit_javascript_result_get_global_context(js_result);
    value = webkit_javascript_result_get_value(js_result);
    if (JSValueIsString(context, value)) {
        JSStringRef js_str_value;
        gchar      *str_value;
        gsize       str_length;

        js_str_value = JSValueToStringCopy(context, value, NULL);
        str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
        str_value = (gchar *)g_malloc(str_length);
        JSStringGetUTF8CString(js_str_value, str_value, str_length);
        JSStringRelease(js_str_value);
        g_free (str_value);
    } else {
        g_warning("Error running javascript: unexpected return value");
    }
    webkit_javascript_result_unref(js_result);
}
开发者ID:fengidri,项目名称:gethar,代码行数:34,代码来源:gethar2.c


示例6: function_read_file

JSValueRef function_read_file(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
                              size_t argc, const JSValueRef args[], JSValueRef *exception) {
    // TODO: implement fully

    if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
        char path[100];
        JSStringRef path_str = JSValueToStringCopy(ctx, args[0], NULL);
        assert(JSStringGetLength(path_str) < 100);
        JSStringGetUTF8CString(path_str, path, 100);
        JSStringRelease(path_str);

        // debug_print_value("read_file", ctx, args[0]);

        time_t last_modified = 0;
        char *contents = get_contents(path, &last_modified);
        if (contents != NULL) {
            JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
            free(contents);

            JSValueRef res[2];
            res[0] = JSValueMakeString(ctx, contents_str);
            res[1] = JSValueMakeNumber(ctx, last_modified);
            return JSObjectMakeArray(ctx, 2, res, NULL);
        }
    }

    return JSValueMakeNull(ctx);
}
开发者ID:mfikes,项目名称:planck,代码行数:28,代码来源:functions.c


示例7: if

JSValueRef JSCCharacterData::appendDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 1 &&
	           JSValueIsString(ctx, arguments[0])) {
		JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception);
		size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg);
		char* localArgBuffer = new char[localArgMaxSize];
		JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize);
		std::string localArg(localArgBuffer);
		JSStringRelease(stringReflocalArg);
		free(localArgBuffer);


		privData->nativeObj->appendData(localArg);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling appendData");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
开发者ID:bjqiwei,项目名称:uscxml,代码行数:27,代码来源:JSCCharacterData.cpp


示例8: arg_to_string

/*
 * Converts an argument to a string.
 *
 * Convert a JSValueRef argument to a g_malloc'd gchar string. Calling function
 * is responsible for g_freeing the string.
 */
static gchar *
arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
	JSStringRef string;
	size_t size;
	gchar *result;

	if (JSValueGetType(context, arg) != kJSTypeString) {
		_mkexception(context, exception, EXPECTSTRING);

		return NULL;
	}

	string = JSValueToStringCopy(context, arg, exception);

	if (!string) {

		return NULL;
	}

	size = JSStringGetMaximumUTF8CStringSize(string);
	result = g_malloc(size);

	if (!result) {

		return NULL;
	}

	JSStringGetUTF8CString(string, result, size);
	JSStringRelease(string);

	return result;
}
开发者ID:sbalneav,项目名称:lightdm-webkit2-greeter,代码行数:38,代码来源:lightdm-webkit2-greeter-ext.c


示例9: setProperty

static bool setProperty(JSContextRef jscore_ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
{
	pdf_jsimp *imp;
	char buf[STRING_BUF_SIZE];
	prop *p;

	priv_data *pdata = JSObjectGetPrivate(object);
	if (pdata == NULL)
		return false;

	JSStringGetUTF8CString(propertyName, buf, STRING_BUF_SIZE);
	p = find_prop(pdata->type->props, buf);
	if (p == NULL)
		return false;

	imp = pdata->type->imp;

	switch(p->type)
	{
		case PROP_FN:
			break;

		case PROP_VAL:
			{
				pdf_jsimp_obj *pval = wrap_val(imp, value);
				p->u.val.set(imp->nat_ctx, pdata->natobj, pval);
				pdf_jsimp_drop_obj(imp, pval);
			}
			break;
	}

	return true;
}
开发者ID:azaleafisitania,项目名称:sumatrapdf,代码行数:33,代码来源:pdf-jsimp-jscore.c


示例10: HyperloopJSStringToStringCopy

/**
 * return a char* from a JSStringRef as string which must be delete when finished
 */
EXPORTAPI char * HyperloopJSStringToStringCopy(JSContextRef ctx, JSStringRef str, JSValueRef *exception)
{
    auto size = JSStringGetMaximumUTF8CStringSize(str);
    auto buf = new char[size];
    JSStringGetUTF8CString(str,buf,size);
    return buf;
}
开发者ID:Sophrinix,项目名称:hyperloop-common,代码行数:10,代码来源:hyperloop.cpp


示例11: element_text_equal_to

static gboolean element_text_equal_to(JSContextRef context, const gchar* text)
{
    JSStringRef scriptString = JSStringCreateWithUTF8CString(
      "window.document.getElementById(\"in\").value;");
    JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
    JSStringRelease(scriptString);

    // If the value isn't a string, the element is probably a div
    // so grab the innerText instead.
    if (!JSValueIsString(context, value)) {
        JSStringRef scriptString = JSStringCreateWithUTF8CString(
          "window.document.getElementById(\"in\").innerText;");
        value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
        JSStringRelease(scriptString);
    }

    g_assert(JSValueIsString(context, value));
    JSStringRef inputString = JSValueToStringCopy(context, value, 0);
    g_assert(inputString);

    gint size = JSStringGetMaximumUTF8CStringSize(inputString);
    gchar* cString = g_malloc(size);
    JSStringGetUTF8CString(inputString, cString, size);
    JSStringRelease(inputString);

    gboolean result = g_utf8_collate(cString, text) == 0;
    g_free(cString);
    return result;
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:29,代码来源:testkeyevents.c


示例12: js_extract_string

static gchar* js_extract_string(JSStringRef string)
{
    gsize size = JSStringGetMaximumUTF8CStringSize(string);
    gchar* gstr = (gchar*) g_malloc(size);
    JSStringGetUTF8CString(string, gstr, size);
    return gstr;
}
开发者ID:purpleKarrot,项目名称:Caravel,代码行数:7,代码来源:js_result.c


示例13: JSValueToStringCopy

char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj)
{
	fz_context *ctx = imp->ctx;
	JSStringRef jstr = JSValueToStringCopy(imp->jscore_ctx, obj->ref, NULL);
	int len;

	if (jstr == NULL)
		return "";

	fz_try(ctx)
	{
		len = JSStringGetMaximumUTF8CStringSize(jstr);
		fz_free(ctx, obj->str);
		obj->str = NULL;
		obj->str = fz_malloc(ctx, len+1);
		JSStringGetUTF8CString(jstr, obj->str, len+1);
	}
	fz_always(ctx)
	{
		JSStringRelease(jstr);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}

	return obj->str;
}
开发者ID:azaleafisitania,项目名称:sumatrapdf,代码行数:28,代码来源:pdf-jsimp-jscore.c


示例14: function_import_script

JSValueRef function_import_script(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
		size_t argc, const JSValueRef args[], JSValueRef* exception) {
	if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeString) {
		JSStringRef path_str_ref = JSValueToStringCopy(ctx, args[0], NULL);
		assert(JSStringGetLength(path_str_ref) < 100);
		char tmp[100];
		tmp[0] = '\0';
		JSStringGetUTF8CString(path_str_ref, tmp, 100);
		JSStringRelease(path_str_ref);

		char *path = tmp;
		if (str_has_prefix(path, "goog/../") == 0) {
			path = path + 8;
		}

		char *source = NULL;
		if (out_path == NULL) {
			source = bundle_get_contents(path);
		} else {
			char *full_path = str_concat(out_path, path);
			source = get_contents(full_path, NULL);
			free(full_path);
		}

		if (source != NULL) {
			evaluate_script(ctx, source, path);
			free(source);
		}
	}

	return JSValueMakeUndefined(ctx);
}
开发者ID:gsnewmark,项目名称:planck,代码行数:32,代码来源:main.c


示例15: JSStringGetMaximumUTF8CStringSize

std::wstring hyperloop::getWString(JSStringRef sValue) {
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return w_str;
}
开发者ID:zkf9971,项目名称:hyperloop,代码行数:8,代码来源:hyperloop.cpp


示例16: JSStringCopyUTF8CString

// Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
char* JSStringCopyUTF8CString(JSStringRef jsString)
{
    size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
    char* utf8 = (char*)malloc(dataSize);
    JSStringGetUTF8CString(jsString, utf8, dataSize);

    return utf8;
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:9,代码来源:WorkQueueItemBal.cpp


示例17: JSStringGetMaximumUTF8CStringSize

Platform::String^ Utils::getPlatformString(JSStringRef sValue) {
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return ref new Platform::String(w_str.c_str());
}
开发者ID:AppWerft,项目名称:hyperloop,代码行数:8,代码来源:Utils.cpp


示例18: JSStringGetLength

char* JSUtils::JSStringRef_to_CharArray(JSStringRef jsString)
{
    char* buf = 0L;
    int len = JSStringGetLength(jsString) + 1;
    buf = (char*) malloc(len*sizeof(char));
    JSStringGetUTF8CString(jsString, buf, len);
    
    return buf;
}
开发者ID:2php,项目名称:osgearth,代码行数:9,代码来源:JSWrappers.cpp


示例19: JSStringToString

String JSStringToString(JSStringRef str)
{
    size_t len = JSStringGetMaximumUTF8CStringSize(str);
    char* buf = new char[len + 1];
    JSStringGetUTF8CString(str, buf, len + 1);

    String result(buf);
    delete[] buf;

    return result;
}
开发者ID:vnmc,项目名称:zephyros,代码行数:11,代码来源:jsbridge_webview.cpp


示例20: spjsdata_get_property_cb

// has property method for callback parameters
JSValueRef spjsdata_get_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
    bool ret = false;
    JSValueRef retval;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char*)malloc(propertySize*sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
    char* data = (char*)JSObjectGetPrivate(object);
    if(strcmp(kParamOTP,property) == 0)
    {

        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamCode,property) == 0)
    {
        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamMessage,property) == 0)
    {
        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamData,property) == 0)
    {
        //JSStringRef sref = JSStringCreateWithUTF8CString(data);
  //JSValueRef ref = JSValueMakeString(ctx, sref);
        
        // json object is passed to e.data
        DPInfo* info = (DPInfo*)JSObjectGetPrivate(object);
//        std::string json = "{\"status\":\"" + (char)info->status + "\",\"version\":\"" + info->version + "\",\"serial\":\"" + info->serial + "\"}";

        char *jsonBuffer = new char[256];
        memset(jsonBuffer, 0, 256);
        sprintf(jsonBuffer, "{\"status\":\"%u\",\"version\":\"%u\",\"serial\":\"%s\",\"passwordFatalCounter\":\"%u\",\"appEventCounter\":\"%lu\"}", info->status, info->version, info->serial.c_str(), info->fatalCounter, info->appEventCounter);
        JSStringRef sref = JSStringCreateWithUTF8CString(jsonBuffer);
        delete []jsonBuffer;

        JSValueRef ref = JSValueMakeFromJSONString(ctx, sref);
        retval = ref;
        ret = true;
    }

    free(property);
    return retval;
}
开发者ID:memedum90,项目名称:demoforios,代码行数:54,代码来源:SPJSDPPlugin.cpp



注:本文中的JSStringGetUTF8CString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JSStringRelease函数代码示例发布时间:2022-05-30
下一篇:
C++ JSStringCreateWithUTF8CString函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap