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