aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-04-03 05:52:32 +0000
committerNick Mathewson <nickm@torproject.org>2005-04-03 05:52:32 +0000
commitff545c3103c55b02b1239465b78033d6b937eda5 (patch)
tree9b340be3b3ef8bf5ed3604aa89248c4b704cbf44
parent11d20d78a03f0befee32c17d50f9e5d294908689 (diff)
downloadtor-ff545c3103c55b02b1239465b78033d6b937eda5.tar.gz
tor-ff545c3103c55b02b1239465b78033d6b937eda5.zip
Add useful smartlist_string_remove function.
svn:r3996
-rw-r--r--src/common/container.c15
-rw-r--r--src/common/container.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c
index 33df51f5b3..f3077176cf 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -118,6 +118,21 @@ void smartlist_remove(smartlist_t *sl, void *element) {
}
}
+/** If there are any string in sl equal to element, remove the first.
+ * Does not preserve order. */
+void
+smartlist_string_remove(smartlist_t *sl, const char *element)
+{
+ int i;
+ size_t len = smartlist_len(sl);
+ for (i = 0; i < len; ++i) {
+ if (!strcmp(element, smartlist_get(sl, i))) {
+ smartlist_del(sl, i);
+ return;
+ }
+ }
+}
+
/** Return true iff some element E of sl has E==element.
*/
int smartlist_isin(const smartlist_t *sl, void *element) {
diff --git a/src/common/container.h b/src/common/container.h
index f003c03d5a..60a13c5965 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -30,6 +30,7 @@ void smartlist_truncate(smartlist_t *sl, int n);
void smartlist_add(smartlist_t *sl, void *element);
void smartlist_add_all(smartlist_t *sl, const smartlist_t *s2);
void smartlist_remove(smartlist_t *sl, void *element);
+void smartlist_string_remove(smartlist_t *sl, const char *element);
int smartlist_isin(const smartlist_t *sl, void *element);
int smartlist_string_isin(const smartlist_t *sl, const char *element);
int smartlist_string_num_isin(const smartlist_t *sl, int num);