From b7af003dbb246039cf6d2bd0ccc9998d74321268 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 8 Oct 2016 00:20:26 +0200 Subject: [PATCH] Add array_{appendall,removeall,appendallu}. --- modules/src/data/array.c | 33 +++++++++++++++++++++++++++++++++ modules/src/data/array.h | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/modules/src/data/array.c b/modules/src/data/array.c index 13c0b6cf6..2847bbdd4 100644 --- a/modules/src/data/array.c +++ b/modules/src/data/array.c @@ -90,5 +90,38 @@ void* array_pop(void* arrayp) return array->item[array->count--]; } +void array_appendall(void* arrayp, void* srcp) +{ + struct array* array = arrayp; + struct array* src = srcp; + int i; + + for (i=0; icount; i++) + array_append(array, src->item[i]); +} + +void array_removeall(void* arrayp, void* srcp) +{ + struct array* array = arrayp; + struct array* src = srcp; + int i; + + for (i=0; icount; i++) + array_remove(array, src->item[i]); +} + +bool array_appendallu(void* arrayp, void* srcp) +{ + struct array* array = arrayp; + struct array* src = srcp; + bool unchanged = true; + int i; + + for (i=0; icount; i++) + unchanged &= array_appendu(array, src->item[i]); + + return unchanged; +} + /* vim: set sw=4 ts=4 expandtab : */ diff --git a/modules/src/data/array.h b/modules/src/data/array.h index 8762d7e6d..6ec497566 100644 --- a/modules/src/data/array.h +++ b/modules/src/data/array.h @@ -27,5 +27,11 @@ extern int array_indexof(void* array, void* value); #define array_push(a, v) array_append(a, v) extern void* array_pop(void* array); +extern void array_appendall(void* dest, void* src); +extern void array_removeall(void* dest, void* src); + +/* Returns false if *any* items were added. */ +extern bool array_appendallu(void* dest, void* src); + #endif