]> git.ipfire.org Git - thirdparty/git.git/blobdiff - strvec.c
The 19th batch
[thirdparty/git.git] / strvec.c
index 178f4f37480e1104e329674964a5d5c24d5ba7e5..f712070f5745d5f998d0846ac4009441dddfa500 100644 (file)
--- a/strvec.c
+++ b/strvec.c
@@ -10,7 +10,7 @@ void strvec_init(struct strvec *array)
        memcpy(array, &blank, sizeof(*array));
 }
 
-static void strvec_push_nodup(struct strvec *array, const char *value)
+void strvec_push_nodup(struct strvec *array, char *value)
 {
        if (array->v == empty_strvec)
                array->v = NULL;
@@ -56,6 +56,26 @@ void strvec_pushv(struct strvec *array, const char **items)
                strvec_push(array, *items);
 }
 
+const char *strvec_replace(struct strvec *array, size_t idx, const char *replacement)
+{
+       char *to_free;
+       if (idx >= array->nr)
+               BUG("index outside of array boundary");
+       to_free = (char *) array->v[idx];
+       array->v[idx] = xstrdup(replacement);
+       free(to_free);
+       return array->v[idx];
+}
+
+void strvec_remove(struct strvec *array, size_t idx)
+{
+       if (idx >= array->nr)
+               BUG("index outside of array boundary");
+       free((char *)array->v[idx]);
+       memmove(array->v + idx, array->v + idx + 1, (array->nr - idx) * sizeof(char *));
+       array->nr--;
+}
+
 void strvec_pop(struct strvec *array)
 {
        if (!array->nr)