Add str_cut_until()
This commit is contained in:
parent
d3b1754e14
commit
f907f1e3dc
6
common.c
6
common.c
|
@ -65,6 +65,12 @@ transform_str (char *s, int (*tolower) (int c))
|
||||||
*s = tolower (*s);
|
*s = tolower (*s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
str_cut_until (const char *s, const char *alphabet)
|
||||||
|
{
|
||||||
|
return xstrndup (s, strcspn (s, alphabet));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
split_str (const char *s, char delimiter, struct str_vector *out)
|
split_str (const char *s, char delimiter, struct str_vector *out)
|
||||||
{
|
{
|
||||||
|
|
10
degesch.c
10
degesch.c
|
@ -2139,7 +2139,7 @@ irc_server_strncmp (struct server *s, const char *a, const char *b, size_t n)
|
||||||
static char *
|
static char *
|
||||||
irc_cut_nickname (const char *prefix)
|
irc_cut_nickname (const char *prefix)
|
||||||
{
|
{
|
||||||
return xstrndup (prefix, strcspn (prefix, "!@"));
|
return str_cut_until (prefix, "!@");
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
@ -6251,8 +6251,7 @@ dump_matching_options
|
||||||
for (size_t i = 0; i < output->len; i++)
|
for (size_t i = 0; i < output->len; i++)
|
||||||
{
|
{
|
||||||
// Yeah, I know
|
// Yeah, I know
|
||||||
const char *line = output->vector[i];
|
char *key = str_cut_until (output->vector[i], " ");
|
||||||
char *key = xstrndup (line, strcspn (line, " "));
|
|
||||||
if (fnmatch (mask, key, 0))
|
if (fnmatch (mask, key, 0))
|
||||||
str_vector_remove (output, i--);
|
str_vector_remove (output, i--);
|
||||||
free (key);
|
free (key);
|
||||||
|
@ -6702,7 +6701,7 @@ handle_command_set_assign
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < all->len; i++)
|
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);
|
handle_command_set_assign_item (ctx, key, new_, add, remove);
|
||||||
free (key);
|
free (key);
|
||||||
}
|
}
|
||||||
|
@ -7837,8 +7836,7 @@ complete_option (struct app_context *ctx, struct completion *data,
|
||||||
char *mask = xstrdup_printf ("%s*", word);
|
char *mask = xstrdup_printf ("%s*", word);
|
||||||
for (size_t i = 0; i < options.len; i++)
|
for (size_t i = 0; i < options.len; i++)
|
||||||
{
|
{
|
||||||
const char *line = options.vector[i];
|
char *key = str_cut_until (options.vector[i], " ");
|
||||||
char *key = xstrndup (line, strcspn (line, " "));
|
|
||||||
if (!fnmatch (mask, key, 0))
|
if (!fnmatch (mask, key, 0))
|
||||||
str_vector_add_owned (output, key);
|
str_vector_add_owned (output, key);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue