mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-12 00:27:53 +02:00
string: add AsciiCaseInsensitive{KeyEqual, Hash} for unordered map
https://httpwg.org/specs/rfc9110.html#rfc.section.5.1 Field names in HTTP headers are case-insensitive. These structs will be used in the headers map to search by key. In libevent field names are also converted to lowercase for comparison: evhttp_find_header() evutil_ascii_strcasecmp() EVUTIL_TOLOWER_()
This commit is contained in:
committed by
Matthew Zipkin
parent
4e300df712
commit
eea38787b9
@@ -13,6 +13,7 @@
|
||||
#include <span.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <charconv>
|
||||
@@ -353,6 +354,20 @@ struct Hex {
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
struct AsciiCaseInsensitiveKeyEqual {
|
||||
bool operator()(std::string_view s1, std::string_view s2) const
|
||||
{
|
||||
return ToLower(s1) == ToLower(s2);
|
||||
}
|
||||
};
|
||||
|
||||
struct AsciiCaseInsensitiveHash {
|
||||
size_t operator()(std::string_view s) const
|
||||
{
|
||||
return std::hash<std::string>{}(ToLower(s));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* ""_hex is a compile-time user-defined literal returning a
|
||||
* `std::array<std::byte>`, equivalent to ParseHex(). Variants provided:
|
||||
|
||||
Reference in New Issue
Block a user