diff options
-rw-r--r-- | common.c | 6 | ||||
-rw-r--r-- | degesch.c | 10 |
2 files changed, 10 insertions, 6 deletions
@@ -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) { @@ -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 |