basic/ordered-set: export networkd function to print string sets

Tests are added.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2019-02-21 12:00:05 +01:00
parent ef79eae09a
commit 53ae3f6467
4 changed files with 34 additions and 20 deletions
+17
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "fileio.h"
#include "ordered-set.h"
#include "strv.h"
@@ -63,3 +64,19 @@ int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l) {
return n;
}
void ordered_set_print(FILE *f, const char *field, OrderedSet *s) {
bool space = false;
Iterator i;
char *p;
if (ordered_set_isempty(s))
return;
fputs(field, f);
ORDERED_SET_FOREACH(p, s, i)
fputs_with_space(f, p, NULL, &space);
fputc('\n', f);
}
+3
View File
@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdio.h>
#include "hashmap.h"
typedef struct OrderedSet OrderedSet;
@@ -56,6 +58,7 @@ int ordered_set_consume(OrderedSet *s, void *p);
int ordered_set_put_strdup(OrderedSet *s, const char *p);
int ordered_set_put_strdupv(OrderedSet *s, char **l);
int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l);
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
#define ORDERED_SET_FOREACH(e, s, i) \
for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); )