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

Function gjs_string_to_intarray

gi/arg.cpp:560–598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

558}
559
560GJS_JSAPI_RETURN_CONVENTION
561static bool gjs_string_to_intarray(JSContext* cx, JS::HandleString str,
562 GITypeTag element_type, void** arr_p,
563 size_t* length) {
564 switch (element_type) {
565 case GI_TYPE_TAG_INT8:
566 case GI_TYPE_TAG_UINT8: {
567 JS::UniqueChars result;
568 if (!gjs_string_to_utf8_n(cx, str, &result, length))
569 return false;
570
571 *arr_p = Gjs::js_chars_to_glib(std::move(result)).release();
572 return true;
573 }
574
575 case GI_TYPE_TAG_INT16:
576 case GI_TYPE_TAG_UINT16: {
577 char16_t* result16;
578 if (!gjs_string_get_char16_data(cx, str, &result16, length))
579 return false;
580 *arr_p = result16;
581 return true;
582 }
583
584 case GI_TYPE_TAG_UNICHAR: {
585 gunichar* result_ucs4;
586 if (!gjs_string_to_ucs4(cx, str, &result_ucs4, length))
587 return false;
588 *arr_p = result_ucs4;
589 return true;
590 }
591
592 default:
593 // can't convert a string to this type
594 gjs_throw(cx, "Cannot convert string to array of '%s'",
595 gi_type_tag_to_string(element_type));
596 return false;
597 }
598}
599
600GJS_JSAPI_RETURN_CONVENTION
601static bool array_to_basic_c_array(JSContext* cx, JS::HandleValue v_array,

Callers 2

Calls 6

gjs_string_to_utf8_nFunction · 0.85
js_chars_to_glibFunction · 0.85
gjs_string_to_ucs4Function · 0.85
gjs_throwFunction · 0.85
releaseMethod · 0.45

Tested by

no test coverage detected