Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
CaseInsensitive.hpp
Go to the documentation of this file.
1#pragma once
3#include <string>
4#include <string_view>
5#include <cctype>
6#include <algorithm>
7
8namespace orbit::utils {
9
11 template <typename StringType>
12 size_t operator()(const StringType& key) const {
13 size_t hash = 0;
14 for (char c : key) {
15 hash ^= std::hash<char>{}(static_cast<char>(std::tolower(static_cast<unsigned char>(c)))) + 0x9e3779b9 + (hash << 6) + (hash >> 2);
16 }
17 return hash;
18 }
19};
20
22 template <typename StringType>
23 bool operator()(const StringType& lhs, const StringType& rhs) const {
24 if (lhs.size() != rhs.size()) return false;
25 for (size_t i = 0; i < lhs.size(); ++i) {
26 if (std::tolower(static_cast<unsigned char>(lhs[i])) != std::tolower(static_cast<unsigned char>(rhs[i]))) {
27 return false;
28 }
29 }
30 return true;
31 }
32};
33
34} // namespace utils
Definition legacy_namespaces.hpp:26
Definition CaseInsensitive.hpp:21
bool operator()(const StringType &lhs, const StringType &rhs) const
Definition CaseInsensitive.hpp:23
Definition CaseInsensitive.hpp:10
size_t operator()(const StringType &key) const
Definition CaseInsensitive.hpp:12