2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-05 08:45:23 +00:00

sset: New function sset_from_delimited_string().

This simplifies code in a couple of places.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-By: Ryan Moats <rmoats@us.ibm.com>
This commit is contained in:
Ben Pfaff
2016-06-24 21:30:39 -07:00
parent 6026f53491
commit 63a10e1e4c
4 changed files with 26 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc.
* Copyright (c) 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,6 +99,25 @@ sset_moved(struct sset *set)
hmap_moved(&set->map);
}
/* Initializes 'set' with substrings of 's' that are delimited by any of the
* characters in 'delimiters'. For example,
* sset_from_delimited_string(&set, "a b,c", " ,");
* initializes 'set' with three strings "a", "b", and "c". */
void
sset_from_delimited_string(struct sset *set, const char *s_,
const char *delimiters)
{
sset_init(set);
char *s = xstrdup(s_);
char *token, *save_ptr = NULL;
for (token = strtok_r(s, delimiters, &save_ptr); token != NULL;
token = strtok_r(NULL, delimiters, &save_ptr)) {
sset_add(set, token);
}
free(s);
}
/* Returns true if 'set' contains no strings, false if it contains at least one
* string. */
bool