2014-09-10 21:32:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-06 14:46:11 +00:00
|
|
|
#include <locale>
|
2014-10-23 19:17:20 +00:00
|
|
|
#include <unordered_map>
|
2022-06-06 14:21:03 +00:00
|
|
|
#include "crow/utility.h"
|
2014-09-10 21:32:41 +00:00
|
|
|
|
|
|
|
namespace crow
|
|
|
|
{
|
2020-11-18 22:13:57 +00:00
|
|
|
/// Hashing function for ci_map (unordered_multimap).
|
2014-09-10 21:32:41 +00:00
|
|
|
struct ci_hash
|
|
|
|
{
|
|
|
|
size_t operator()(const std::string& key) const
|
|
|
|
{
|
|
|
|
std::size_t seed = 0;
|
|
|
|
std::locale locale;
|
|
|
|
|
2021-11-25 11:45:38 +00:00
|
|
|
for (auto c : key)
|
2022-06-06 14:46:11 +00:00
|
|
|
hash_combine(seed, std::toupper(c, locale));
|
2014-09-10 21:32:41 +00:00
|
|
|
|
|
|
|
return seed;
|
|
|
|
}
|
2022-06-06 14:46:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static inline void hash_combine(std::size_t& seed, char v)
|
|
|
|
{
|
|
|
|
std::hash<char> hasher;
|
|
|
|
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
|
|
|
}
|
2014-09-10 21:32:41 +00:00
|
|
|
};
|
|
|
|
|
2020-11-18 22:13:57 +00:00
|
|
|
/// Equals function for ci_map (unordered_multimap).
|
2014-09-10 21:32:41 +00:00
|
|
|
struct ci_key_eq
|
|
|
|
{
|
|
|
|
bool operator()(const std::string& l, const std::string& r) const
|
|
|
|
{
|
2022-06-06 14:21:03 +00:00
|
|
|
return utility::string_equals(l, r);
|
2014-09-10 21:32:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using ci_map = std::unordered_multimap<std::string, std::string, ci_hash, ci_key_eq>;
|
2021-11-25 11:45:38 +00:00
|
|
|
} // namespace crow
|