From 4cd302a1ebd44eafe5ac57062288436ab41b1220 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 28 Dec 2006 21:29:03 +0000 Subject: [PATCH] r11722@Kushana: nickm | 2006-12-28 13:51:42 -0500 Add a helper function for case-insensitive search through a smartlist svn:r9198 --- src/common/container.c | 14 ++++++++++++++ src/common/container.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/common/container.c b/src/common/container.c index 6dae0bb932..659e1346d1 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -197,6 +197,20 @@ smartlist_string_isin(const smartlist_t *sl, const char *element) return 0; } +/** Return true iff sl has some element E such that + * !strcasecmp(E,element) + */ +int +smartlist_string_isin_case(const smartlist_t *sl, const char *element) +{ + int i; + if (!sl) return 0; + for (i=0; i < sl->num_used; i++) + if (strcasecmp((const char*)sl->list[i],element)==0) + return 1; + return 0; +} + /** Return true iff sl has some element E such that E is equal * to the decimal encoding of num. */ diff --git a/src/common/container.h b/src/common/container.h index 5f0417cf4d..a6b7b56adb 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -35,6 +35,8 @@ void smartlist_string_remove(smartlist_t *sl, const char *element); int smartlist_isin(const smartlist_t *sl, const void *element) ATTR_PURE; int smartlist_string_isin(const smartlist_t *sl, const char *element) ATTR_PURE; +int smartlist_string_isin_case(const smartlist_t *sl, const char *element) + ATTR_PURE; int smartlist_string_num_isin(const smartlist_t *sl, int num) ATTR_PURE; int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2) ATTR_PURE;