Extend split_str() for multiple split chars
This commit is contained in:
parent
f11635ed7f
commit
9b22d72fd1
6
common.c
6
common.c
@ -44,10 +44,10 @@
|
|||||||
// --- To be moved to liberty --------------------------------------------------
|
// --- To be moved to liberty --------------------------------------------------
|
||||||
|
|
||||||
static void
|
static void
|
||||||
split_str (const char *s, char delimiter, struct str_vector *out)
|
split_str (const char *s, const char *delimiters, struct str_vector *out)
|
||||||
{
|
{
|
||||||
const char *begin = s, *end;
|
const char *begin = s, *end;
|
||||||
while ((end = strchr (begin, delimiter)))
|
while ((end = strpbrk (begin, delimiters)))
|
||||||
{
|
{
|
||||||
str_vector_add_owned (out, xstrndup (begin, end - begin));
|
str_vector_add_owned (out, xstrndup (begin, end - begin));
|
||||||
begin = ++end;
|
begin = ++end;
|
||||||
@ -1245,7 +1245,7 @@ config_item_get (struct config_item *self, const char *path, struct error **e)
|
|||||||
|
|
||||||
struct str_vector v;
|
struct str_vector v;
|
||||||
str_vector_init (&v);
|
str_vector_init (&v);
|
||||||
split_str (path, '.', &v);
|
split_str (path, ".", &v);
|
||||||
|
|
||||||
struct config_item *result = NULL;
|
struct config_item *result = NULL;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
@ -3965,7 +3965,7 @@ on_irc_autojoin_timeout (void *user_data)
|
|||||||
{
|
{
|
||||||
struct str_vector v;
|
struct str_vector v;
|
||||||
str_vector_init (&v);
|
str_vector_init (&v);
|
||||||
split_str (autojoin, ',', &v);
|
split_str (autojoin, ",", &v);
|
||||||
for (size_t i = 0; i < v.len; i++)
|
for (size_t i = 0; i < v.len; i++)
|
||||||
{
|
{
|
||||||
irc_send (s, "JOIN :%s", v.vector[i]);
|
irc_send (s, "JOIN :%s", v.vector[i]);
|
||||||
@ -7311,7 +7311,7 @@ handle_command_set_add
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
struct str_vector items;
|
struct str_vector items;
|
||||||
str_vector_init (&items);
|
str_vector_init (&items);
|
||||||
split_str (item->value.string.str, ',', &items);
|
split_str (item->value.string.str, ",", &items);
|
||||||
if (items.len == 1 && !*items.vector[0])
|
if (items.len == 1 && !*items.vector[0])
|
||||||
str_vector_reset (&items);
|
str_vector_reset (&items);
|
||||||
|
|
||||||
@ -7334,7 +7334,7 @@ handle_command_set_remove
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
struct str_vector items;
|
struct str_vector items;
|
||||||
str_vector_init (&items);
|
str_vector_init (&items);
|
||||||
split_str (item->value.string.str, ',', &items);
|
split_str (item->value.string.str, ",", &items);
|
||||||
if (items.len == 1 && !*items.vector[0])
|
if (items.len == 1 && !*items.vector[0])
|
||||||
str_vector_reset (&items);
|
str_vector_reset (&items);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user