MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_string_to_utf8

Function gjs_string_to_utf8

gjs/jsapi-util-string.cpp:88–96  ·  view source on GitHub ↗

* gjs_string_to_utf8: * @cx: JSContext * @value: a JS::Value containing a string * * Converts the JSString in @value to UTF-8 and puts it in @utf8_string_p. * * This function is a convenience wrapper around JS_EncodeStringToUTF8() that * typechecks the JS::Value and throws an exception if it's the wrong type. * Don't use this function if you already have a JS::RootedString, or if you * kn

Source from the content-addressed store, hash-verified

86 * Returns: Unique UTF8 chars, empty on exception throw.
87 */
88JS::UniqueChars gjs_string_to_utf8(JSContext* cx, const JS::Value value) {
89 if (!value.isString()) {
90 gjs_throw(cx, "Value is not a string, cannot convert to UTF-8");
91 return nullptr;
92 }
93
94 JS::RootedString str(cx, value.toString());
95 return JS_EncodeStringToUTF8(cx, str);
96}
97
98/**
99 * gjs_string_to_utf8_n:

Calls 2

gjs_throwFunction · 0.85
toStringMethod · 0.45