Add array_replace().
authorDavid Given <dg@cowlark.com>
Mon, 5 Dec 2016 23:11:40 +0000 (00:11 +0100)
committerDavid Given <dg@cowlark.com>
Mon, 5 Dec 2016 23:11:40 +0000 (00:11 +0100)
modules/src/data/array.c
modules/src/data/array.h

index 2847bbd..3309446 100644 (file)
@@ -82,6 +82,18 @@ void array_remove(void* arrayp, void* value)
     }
 }
 
+void array_replace(void* arrayp, void* from, void* to)
+{
+    struct array* array = arrayp;
+    int i;
+
+    for (i=0; i<array->count; i++)
+    {
+        if (array->item[i] == from)
+            array->item[i] = to;
+    }
+}
+
 void* array_pop(void* arrayp)
 {
     struct array* array = arrayp;
index 6ec4975..014243d 100644 (file)
@@ -23,6 +23,7 @@ extern void array_insert(void* array, void* value, int before);
 extern void array_remove(void* array, void* value);
 extern bool array_contains(void* array, void* value);
 extern int array_indexof(void* array, void* value);
+extern void array_replace(void* array, void* from, void* to);
 
 #define array_push(a, v) array_append(a, v)
 extern void* array_pop(void* array);