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

Function from_latin1

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

Source from the content-addressed store, hash-verified

245 * type, by what the compiler believes is the most efficient method possible */
246template <typename T>
247GJS_JSAPI_RETURN_CONVENTION
248static bool from_latin1(JSContext* cx, JSString* str, T** data_p,
249 size_t* len_p) {
250 /* No garbage collection should be triggered while we are using the string's
251 * chars. Crash if that happens. */
252 JS::AutoCheckCannotGC nogc;
253
254 const JS::Latin1Char* js_data =
255 JS_GetLatin1StringCharsAndLength(cx, nogc, str, len_p);
256 if (js_data == nullptr)
257 return false;
258
259 /* Unicode codepoints 0x00-0xFF are the same as Latin-1 codepoints, so we
260 * can preserve the string length and simply copy the codepoints to an array
261 * of different-sized ints */
262
263 *data_p = g_new(T, *len_p);
264
265 // This will probably use a loop, unfortunately
266 std::copy(js_data, js_data + *len_p, *data_p);
267 return true;
268}
269
270/**
271 * gjs_string_get_char16_data:

Callers 2

gjs_string_to_ucs4Function · 0.85

Calls 1

copyFunction · 0.85

Tested by

no test coverage detected