Add str_vector_steal()

This commit is contained in:
Přemysl Eric Janouch 2015-06-26 22:20:37 +02:00
parent b29f470583
commit 439bc3acd3

View File

@ -401,13 +401,20 @@ str_vector_add_vector (struct str_vector *self, char **vector)
str_vector_add (self, *vector++); str_vector_add (self, *vector++);
} }
static char *
str_vector_steal (struct str_vector *self, size_t i)
{
hard_assert (i < self->len);
char *tmp = self->vector[i];
memmove (self->vector + i, self->vector + i + 1,
(self->len-- - i) * sizeof *self->vector);
return tmp;
}
static void static void
str_vector_remove (struct str_vector *self, size_t i) str_vector_remove (struct str_vector *self, size_t i)
{ {
hard_assert (i < self->len); free (str_vector_steal (self, i));
free (self->vector[i]);
memmove (self->vector + i, self->vector + i + 1,
(self->len-- - i) * sizeof *self->vector);
} }
// --- Dynamically allocated strings ------------------------------------------- // --- Dynamically allocated strings -------------------------------------------