glib-aux: add nm_strv_ptrarray_to_strv() helper

This will replace _nm_utils_ptrarray_to_strv().

One difference is, that this will fail an assertion if there are any
NULL string in the GPtrArray.
This commit is contained in:
Thomas Haller 2023-11-17 09:25:48 +01:00
parent 541979d098
commit 7c16eb36ab
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -2536,6 +2536,21 @@ nm_strv_ptrarray_get_unsafe(GPtrArray *arr, guint *out_len)
return (const char *const *) arr->pdata;
}
static inline char **
nm_strv_ptrarray_to_strv_full(const GPtrArray *a, gboolean not_null)
{
if (!a)
return not_null ? nm_strv_empty_new() : NULL;
return nm_strv_dup_full((const char *const *) a->pdata, a->len, TRUE, TRUE);
}
static inline char **
nm_strv_ptrarray_to_strv(const GPtrArray *a)
{
/* Returns never NULL ("not_null"!) */
return nm_strv_ptrarray_to_strv_full(a, TRUE);
}
static inline GPtrArray *
nm_strv_ptrarray_clone(const GPtrArray *src, gboolean null_if_empty)
{