Add str_cut_until()

This commit is contained in:
Přemysl Eric Janouch 2015-07-09 00:10:06 +02:00
parent d3b1754e14
commit f907f1e3dc
2 changed files with 10 additions and 6 deletions

View File

@ -65,6 +65,12 @@ transform_str (char *s, int (*tolower) (int c))
*s = tolower (*s);
}
static char *
str_cut_until (const char *s, const char *alphabet)
{
return xstrndup (s, strcspn (s, alphabet));
}
static void
split_str (const char *s, char delimiter, struct str_vector *out)
{

View File

@ -2139,7 +2139,7 @@ irc_server_strncmp (struct server *s, const char *a, const char *b, size_t n)
static char *
irc_cut_nickname (const char *prefix)
{
return xstrndup (prefix, strcspn (prefix, "!@"));
return str_cut_until (prefix, "!@");
}
static const char *
@ -6251,8 +6251,7 @@ dump_matching_options
for (size_t i = 0; i < output->len; i++)
{
// Yeah, I know
const char *line = output->vector[i];
char *key = xstrndup (line, strcspn (line, " "));
char *key = str_cut_until (output->vector[i], " ");
if (fnmatch (mask, key, 0))
str_vector_remove (output, i--);
free (key);
@ -6702,7 +6701,7 @@ handle_command_set_assign
}
for (size_t i = 0; i < all->len; i++)
{
char *key = xstrndup (all->vector[i], strcspn (all->vector[i], " "));
char *key = str_cut_until (all->vector[i], " ");
handle_command_set_assign_item (ctx, key, new_, add, remove);
free (key);
}
@ -7837,8 +7836,7 @@ complete_option (struct app_context *ctx, struct completion *data,
char *mask = xstrdup_printf ("%s*", word);
for (size_t i = 0; i < options.len; i++)
{
const char *line = options.vector[i];
char *key = xstrndup (line, strcspn (line, " "));
char *key = str_cut_until (options.vector[i], " ");
if (!fnmatch (mask, key, 0))
str_vector_add_owned (output, key);
else