aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/strings.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 79dac8700..4f5e326cf 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -23,6 +23,8 @@
#ifndef _ASTERISK_STRINGS_H
#define _ASTERISK_STRINGS_H
+#include <ctype.h>
+
#include "asterisk/inline_api.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
@@ -702,4 +704,21 @@ static force_inline int ast_str_hash(const char *str)
return abs(hash);
}
+/*!
+ * \brief Compute a hash value on a case-insensitive string
+ *
+ * Uses the same hash algorithm as ast_str_hash, but converts
+ * all characters to lowercase prior to computing a hash. This
+ * allows for easy case-insensitive lookups in a hash table.
+ */
+static force_inline int ast_str_case_hash(const char *str)
+{
+ int hash = 5381;
+
+ while (*str) {
+ hash = hash * 33 ^ tolower(*str++);
+ }
+
+ return abs(hash);
+}
#endif /* _ASTERISK_STRINGS_H */