Merge cstr_split() and cstr_split_ignore_empty()

This commit is contained in:
Přemysl Eric Janouch 2016-10-09 09:45:27 +02:00
parent a34ce0b6b8
commit 0b77bdeaf9
Signed by: p
GPG Key ID: B715679E3A361BE6
2 changed files with 8 additions and 21 deletions

View File

@ -66,7 +66,7 @@ irc_parse_message_tags (const char *tags, struct str_map *out)
{
struct str_vector v;
str_vector_init (&v);
cstr_split_ignore_empty (tags, ';', &v);
cstr_split (tags, ";", true, &v);
for (size_t i = 0; i < v.len; i++)
{

View File

@ -2899,30 +2899,17 @@ base64_encode (const void *data, size_t len, struct str *output)
// --- Utilities ---------------------------------------------------------------
static void
cstr_split (const char *s, const char *delimiters, struct str_vector *out)
cstr_split (const char *s, const char *delimiters, bool ignore_empty,
struct str_vector *out)
{
const char *begin = s, *end;
while ((end = strpbrk (begin, delimiters)))
{
if (!ignore_empty || begin != end)
str_vector_add_owned (out, xstrndup (begin, end - begin));
begin = ++end;
}
str_vector_add (out, begin);
}
static void
cstr_split_ignore_empty (const char *s, char delimiter, struct str_vector *out)
{
const char *begin = s, *end;
while ((end = strchr (begin, delimiter)))
{
if (begin != end)
str_vector_add_owned (out, xstrndup (begin, end - begin));
begin = ++end;
}
if (*begin)
if (!ignore_empty || *begin)
str_vector_add (out, begin);
}
@ -3219,7 +3206,7 @@ get_xdg_config_dirs (struct str_vector *out)
const char *xdg_config_dirs;
if (!(xdg_config_dirs = getenv ("XDG_CONFIG_DIRS")))
xdg_config_dirs = "/etc/xdg";
cstr_split_ignore_empty (xdg_config_dirs, ':', out);
cstr_split (xdg_config_dirs, ":", true, out);
}
static char *
@ -3246,7 +3233,7 @@ get_xdg_data_dirs (struct str_vector *out)
const char *xdg_data_dirs;
if (!(xdg_data_dirs = getenv ("XDG_DATA_DIRS")))
xdg_data_dirs = "/usr/local/share/:/usr/share/";
cstr_split_ignore_empty (xdg_data_dirs, ':', out);
cstr_split (xdg_data_dirs, ":", true, out);
}
static char *
@ -4635,7 +4622,7 @@ config_item_get (struct config_item *self, const char *path, struct error **e)
struct str_vector v;
str_vector_init (&v);
cstr_split (path, ".", &v);
cstr_split (path, ".", false, &v);
struct config_item *result = NULL;
size_t i = 0;