strv: add helper to extend strv from both sides

Also, use the more correct type of 'const char* const*' for the input strv.
This requires adding the cast in a few places, but also allows to remove some
casts in others.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-07 18:49:44 +01:00
parent 4bf32eac52
commit 9bc7493098
7 changed files with 29 additions and 10 deletions
+17 -1
View File
@@ -527,6 +527,22 @@ TEST(strv_sort) {
assert_se(streq(input_table[4], "durian"));
}
TEST(strv_extend_strv_biconcat) {
_cleanup_strv_free_ char **a = NULL, **b = NULL;
a = strv_new("without", "suffix");
b = strv_new("with", "suffix");
assert_se(a);
assert_se(b);
assert_se(strv_extend_strv_biconcat(&a, "prefix_", (const char* const*) b, "_suffix") >= 0);
assert_se(streq(a[0], "without"));
assert_se(streq(a[1], "suffix"));
assert_se(streq(a[2], "prefix_with_suffix"));
assert_se(streq(a[3], "prefix_suffix_suffix"));
}
TEST(strv_extend_strv_concat) {
_cleanup_strv_free_ char **a = NULL, **b = NULL;
@@ -535,7 +551,7 @@ TEST(strv_extend_strv_concat) {
assert_se(a);
assert_se(b);
assert_se(strv_extend_strv_concat(&a, b, "_suffix") >= 0);
assert_se(strv_extend_strv_concat(&a, (const char* const*) b, "_suffix") >= 0);
assert_se(streq(a[0], "without"));
assert_se(streq(a[1], "suffix"));