Skip to content

Commit 4394481

Browse files
committed
Avoid C++11 features.
1 parent dde9163 commit 4394481

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lua/main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ extern "C"
1010
#include "../common/HTTPS.h"
1111
#include "../common/config.h"
1212

13-
static std::set<std::string> validMethod {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"};
13+
static std::string validMethod[] = {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"};
14+
15+
static int str_toupper(char c)
16+
{
17+
unsigned char uc = (unsigned char) c;
18+
return toupper(uc);
19+
}
1420

1521
static std::string w_checkstring(lua_State *L, int idx)
1622
{
@@ -41,13 +47,15 @@ static void w_readheaders(lua_State *L, int idx, HTTPSClient::header_map &header
4147

4248
static std::string w_optmethod(lua_State *L, int idx, const std::string &defaultMethod)
4349
{
50+
std::string *const validMethodEnd = validMethod + sizeof(validMethod) / sizeof(std::string);
51+
4452
if (lua_isnoneornil(L, idx))
4553
return defaultMethod;
4654

4755
std::string str = w_checkstring(L, idx);
48-
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return toupper(c); });
56+
std::transform(str.begin(), str.end(), str.begin(), str_toupper);
4957

50-
if (validMethod.find(str) == validMethod.end())
58+
if (std::find(validMethod, validMethodEnd, str) == validMethodEnd)
5159
luaL_argerror(L, idx, "expected one of \"get\", \"head\", \"post\", \"put\", \"delete\", or \"patch\"");
5260

5361
return str;

0 commit comments

Comments
 (0)