MCPcopy Create free account
hub / github.com/git/git / strvec_splice

Function strvec_splice

strvec.c:59–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59void strvec_splice(struct strvec *array, size_t idx, size_t len,
60 const char **replacement, size_t replacement_len)
61{
62 if (idx + len > array->nr)
63 BUG("range outside of array boundary");
64 if (replacement_len > len) {
65 if (array->v == empty_strvec)
66 array->v = NULL;
67 ALLOC_GROW(array->v, array->nr + (replacement_len - len) + 1,
68 array->alloc);
69 array->v[array->nr + (replacement_len - len)] = NULL;
70 }
71 for (size_t i = 0; i < len; i++)
72 free((char *)array->v[idx + i]);
73 if ((replacement_len != len) && array->nr)
74 memmove(array->v + idx + replacement_len, array->v + idx + len,
75 (array->nr - idx - len + 1) * sizeof(char *));
76 array->nr += replacement_len - len;
77 for (size_t i = 0; i < replacement_len; i++)
78 array->v[idx + i] = xstrdup(replacement[i]);
79}
80
81const char *strvec_replace(struct strvec *array, size_t idx, const char *replacement)
82{

Calls 1

xstrdupFunction · 0.85