Skip to content

Commit

Permalink
string_view support
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Nov 27, 2023
1 parent 115a786 commit a4680f1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
#define CPPHTTPLIB_LISTEN_BACKLOG 5
#endif

#if __cpp_lib_string_view >= 201606L
#define CPPHTTPLIB_STRING_VIEW_SUPPORT
#endif

/*
* Headers
*/
Expand Down Expand Up @@ -234,6 +238,10 @@ using socket_t = int;
#include <unordered_set>
#include <utility>

#ifdef CPPHTTPLIB_STRING_VIEW_SUPPORT
#include <string_view>
#endif

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
#ifdef _WIN32
#include <wincrypt.h>
Expand Down Expand Up @@ -314,13 +322,26 @@ make_unique(std::size_t n) {
}

struct ci {
#if CPPHTTPLIB_STRING_VIEW_SUPPORT
using is_transparent = void;

bool operator()(const std::string_view s1, const std::string_view s2) const {
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(),
s2.end(),
[](unsigned char c1, unsigned char c2) {
return ::tolower(c1) < ::tolower(c2);
});
}

#else
bool operator()(const std::string &s1, const std::string &s2) const {
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(),
s2.end(),
[](unsigned char c1, unsigned char c2) {
return ::tolower(c1) < ::tolower(c2);
});
}
#endif
};

// This is based on
Expand Down

0 comments on commit a4680f1

Please sign in to comment.