GNOME Bugzilla – Bug 631210
Missing strv functions
Last modified: 2018-05-24 12:47:37 UTC
There is very useful data type half-supported by glib - the NULL-ended array of pointers to strings. Some functions are missing: - insert at position - delete at position - search It is not a problem to implement them when they are needed - but perhaps it would be useful to have them in glib code
These functions become of more importance since people are moving stuff to gsettings which have set_strv and get_strv functions.
Another useful one: "behead" - free first element and shift all pointers down.
Created attachment 171681 [details] Minimal set of useful additions
I don't think we want to make GStrv modifiable, all the array resizing magic is already in GPtrArray: GPtrArray *array; GStrv strv; array = g_ptr_array_sized_new (2); g_ptr_array_add (array, g_strdup ("foo")); g_ptr_array_add (array, g_strdup ("bar")); ... g_ptr_array_add (array, NULL); strv = g_ptr_array_free (array, FALSE);
I could help to have g_ptr_array_set_null_terminated() though. Like GArray's zero_terminated. Like that array->pdata is always a GStrv.
*** Bug 708250 has been marked as a duplicate of this bug. ***
It's come up a few times that it may actually be useful to have a GPtrArray subset functionality specifically useful for strings (just as GPtrArray is a GArray for pointers).
g_strv_contains() is implemented in bug #685880.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/353.