From: Michael Haggerty <mhagger@alum.mit.edu>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH 1/5] string_list: add a function string_list_remove_empty_items()
Date: Sun, 4 Nov 2012 08:07:06 +0100 [thread overview]
Message-ID: <1352012830-13591-2-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1352012830-13591-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/technical/api-string-list.txt | 9 ++++++++-
string-list.c | 9 +++++++++
string-list.h | 7 +++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 94d7a2b..7386bca 100644
--- a/Documentation/technical/api-string-list.txt
+++ b/Documentation/technical/api-string-list.txt
@@ -38,7 +38,8 @@ member (you need this if you add things later) and you should set the
`unsorted_string_list_delete_item`.
. Can remove items not matching a criterion from a sorted or unsorted
- list using `filter_string_list`.
+ list using `filter_string_list`, or remove empty strings using
+ `string_list_remove_empty_items`.
. Finally it should free the list using `string_list_clear`.
@@ -75,6 +76,12 @@ Functions
to be deleted. Preserve the order of the items that are
retained.
+`string_list_remove_empty_items`::
+
+ Remove any empty strings from the list. If free_util is true,
+ call free() on the util members of any items that have to be
+ deleted. Preserve the order of the items that are retained.
+
`string_list_longest_prefix`::
Return the longest string within a string_list that is a
diff --git a/string-list.c b/string-list.c
index c54b816..397e6cf 100644
--- a/string-list.c
+++ b/string-list.c
@@ -136,6 +136,15 @@ void filter_string_list(struct string_list *list, int free_util,
list->nr = dst;
}
+static int item_is_not_empty(struct string_list_item *item, void *unused)
+{
+ return *item->string != '\0';
+}
+
+void string_list_remove_empty_items(struct string_list *list, int free_util) {
+ filter_string_list(list, free_util, item_is_not_empty, NULL);
+}
+
char *string_list_longest_prefix(const struct string_list *prefixes,
const char *string)
{
diff --git a/string-list.h b/string-list.h
index 5efd07b..c50b0d0 100644
--- a/string-list.h
+++ b/string-list.h
@@ -39,6 +39,13 @@ void filter_string_list(struct string_list *list, int free_util,
string_list_each_func_t want, void *cb_data);
/*
+ * Remove any empty strings from the list. If free_util is true, call
+ * free() on the util members of any items that have to be deleted.
+ * Preserve the order of the items that are retained.
+ */
+void string_list_remove_empty_items(struct string_list *list, int free_util);
+
+/*
* Return the longest string in prefixes that is a prefix (in the
* sense of prefixcmp()) of string, or NULL if no such prefix exists.
* This function does not require the string_list to be sorted (it
--
1.8.0
next prev parent reply other threads:[~2012-11-04 7:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-04 7:07 [PATCH 0/5] Use string_lists when processing notes Michael Haggerty
2012-11-04 7:07 ` Michael Haggerty [this message]
2012-11-04 7:07 ` [PATCH 2/5] Initialize sort_uniq_list using named constant Michael Haggerty
2012-11-04 7:07 ` [PATCH 3/5] combine_notes_cat_sort_uniq(): sort and dedup lines all at once Michael Haggerty
2012-11-04 7:07 ` [PATCH 4/5] notes: fix handling of colon-separated values Michael Haggerty
2012-11-04 7:07 ` [PATCH 5/5] string_list_add_refs_from_colon_sep(): use string_list_split() Michael Haggerty
2012-11-04 11:57 ` Jeff King
[not found] ` <CALKQrgebzH5vJUQVNxTks0Nq_3OZBWrb-cLDkABxnGJJqfB7gQ@mail.gmail.com>
[not found] ` <5098C29A.4010901@alum.mit.edu>
2012-11-06 14:20 ` [PATCH 0/5] Use string_lists when processing notes Johan Herland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352012830-13591-2-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).