浏览代码

Avoid C++11 features.

Miku AuahDark 3 年之前
父节点
当前提交
4394481ab9
共有 1 个文件被更改,包括 11 次插入3 次删除
  1. 11 3
      src/lua/main.cpp

+ 11 - 3
src/lua/main.cpp

@@ -10,7 +10,13 @@ extern "C"
 #include "../common/HTTPS.h"
 #include "../common/HTTPS.h"
 #include "../common/config.h"
 #include "../common/config.h"
 
 
-static std::set<std::string> validMethod {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"};
+static std::string validMethod[] = {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"};
+
+static int str_toupper(char c)
+{
+	unsigned char uc = (unsigned char) c;
+	return toupper(uc);
+}
 
 
 static std::string w_checkstring(lua_State *L, int idx)
 static std::string w_checkstring(lua_State *L, int idx)
 {
 {
@@ -41,13 +47,15 @@ static void w_readheaders(lua_State *L, int idx, HTTPSClient::header_map &header
 
 
 static std::string w_optmethod(lua_State *L, int idx, const std::string &defaultMethod)
 static std::string w_optmethod(lua_State *L, int idx, const std::string &defaultMethod)
 {
 {
+	std::string *const validMethodEnd = validMethod + sizeof(validMethod) / sizeof(std::string);
+
 	if (lua_isnoneornil(L, idx))
 	if (lua_isnoneornil(L, idx))
 		return defaultMethod;
 		return defaultMethod;
 
 
 	std::string str = w_checkstring(L, idx);
 	std::string str = w_checkstring(L, idx);
-	std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { return toupper(c); });
+	std::transform(str.begin(), str.end(), str.begin(), str_toupper);
 
 
-	if (validMethod.find(str) == validMethod.end())
+	if (std::find(validMethod, validMethodEnd, str) == validMethodEnd)
 		luaL_argerror(L, idx, "expected one of \"get\", \"head\", \"post\", \"put\", \"delete\", or \"patch\"");
 		luaL_argerror(L, idx, "expected one of \"get\", \"head\", \"post\", \"put\", \"delete\", or \"patch\"");
 
 
 	return str;
 	return str;