From d45c25b239c378e38de314667a39df29868c6c67 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 15 Jun 2019 21:09:12 +0100 Subject: [PATCH] move mutt_str_split() to list.c Remove List dependency from string.c --- email/tags.c | 2 +- mutt/list.c | 29 +++++++++++++++++++++++++++++ mutt/list.h | 1 + mutt/string.c | 31 ------------------------------- mutt/string2.h | 1 - 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/email/tags.c b/email/tags.c index b23aa1927..c843f645d 100644 --- a/email/tags.c +++ b/email/tags.c @@ -190,7 +190,7 @@ bool driver_tags_replace(struct TagHead *head, char *tags) if (tags) { - struct ListHead hsplit = mutt_str_split(tags, ' '); + struct ListHead hsplit = mutt_list_str_split(tags, ' '); struct ListNode *np = NULL; STAILQ_FOREACH(np, &hsplit, entries) { diff --git a/mutt/list.c b/mutt/list.c index f6275f19f..d136650f4 100644 --- a/mutt/list.c +++ b/mutt/list.c @@ -237,3 +237,32 @@ bool mutt_list_compare(const struct ListHead *ah, const struct ListHead *bh) return true; } + +/** + * mutt_list_str_split - Split a string into a list using a separator char + * @param src String to split + * @param sep Word separator + */ +struct ListHead mutt_list_str_split(const char *src, char sep) +{ + struct ListHead head = STAILQ_HEAD_INITIALIZER(head); + + if (!src || !*src) + return head; + + while (true) + { + const char *start = src; + while (*src && (*src != sep)) + src++; + + mutt_list_insert_tail(&head, mutt_str_substr_dup(start, src)); + + if (!*src) + break; + + src++; + } + + return head; +} diff --git a/mutt/list.h b/mutt/list.h index d5ee8df7b..3ee70a57c 100644 --- a/mutt/list.h +++ b/mutt/list.h @@ -52,5 +52,6 @@ struct ListNode *mutt_list_insert_after(struct ListHead *h, struct ListNode *n, struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s); struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s); bool mutt_list_match(const char *s, struct ListHead *h); +struct ListHead mutt_list_str_split(const char *src, char sep); #endif /* MUTT_LIB_LIST_H */ diff --git a/mutt/string.c b/mutt/string.c index e841df7b4..e6d44546b 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -38,11 +38,9 @@ #include #include #include "exit.h" -#include "list.h" #include "logging.h" #include "memory.h" #include "message.h" -#include "queue.h" #include "string2.h" #ifdef HAVE_SYSEXITS_H #include @@ -1188,35 +1186,6 @@ const char *mutt_str_strcasestr(const char *haystack, const char *needle) return NULL; } -/** - * mutt_str_split - return list of the words of the strings - * @param src String to split - * @param sep Word separator - */ -struct ListHead mutt_str_split(const char *src, char sep) -{ - struct ListHead head = STAILQ_HEAD_INITIALIZER(head); - - if (!src || !*src) - return head; - - while (true) - { - const char *start = src; - while (*src && (*src != sep)) - src++; - - mutt_list_insert_tail(&head, mutt_str_substr_dup(start, src)); - - if (!*src) - break; - - src++; - } - - return head; -} - #ifdef HAVE_VASPRINTF /** * mutt_str_asprintf - Format a string, allocating space as necessary diff --git a/mutt/string2.h b/mutt/string2.h index 89df8cb45..ae191e79a 100644 --- a/mutt/string2.h +++ b/mutt/string2.h @@ -93,7 +93,6 @@ void mutt_str_replace(char **p, const char *s); const char *mutt_str_rstrnstr(const char *haystack, size_t haystack_length, const char *needle); char * mutt_str_skip_email_wsp(const char *s); char * mutt_str_skip_whitespace(const char *p); -struct ListHead mutt_str_split(const char *src, char sep); int mutt_str_strcasecmp(const char *a, const char *b); size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs); const char *mutt_str_strcasestr(const char *haystack, const char *needle); -- 2.40.0