2 * Copyright (c) 2014, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
16 struct dn_char_traits : public std::char_traits<char> {
17 static bool eq(char c1, char c2) {
18 return ::tolower(c1) == ::tolower(c2);
21 static bool ne(char c1, char c2) {
22 return ::tolower(c1) != ::tolower(c2);
25 static bool lt(char c1, char c2) {
26 return ::tolower(c1) < ::tolower(c2);
29 static int compare(const char* s1, const char* s2, size_t n) {
31 if(::tolower(*s1) < ::tolower(*s2) ) {
34 if(::tolower(*s1) > ::tolower(*s2) ) {
43 static const char* find(const char* s, size_t n, char a) {
44 char la = ::tolower(a);
46 if(::tolower(*s) == la) {
56 // Case insensitive string
57 typedef std::basic_string<char, dn_char_traits> DNString;
59 struct DNStringHash : public std::hash<std::string> {
60 size_t operator()(const DNString& s) const noexcept {
61 size_t h = static_cast<size_t>(0xc70f6907UL);
62 const char* d = s.data();
63 for (size_t i = 0; i < s.length(); ++i) {
64 char a = ::tolower(*d++);
65 h = std::_Hash_impl::hash(&a, sizeof(a), h);