Progress on mingw driver

This commit is contained in:
2021-10-07 14:58:20 -04:00
parent bce756d1fd
commit e7f55a2411
16 changed files with 405 additions and 172 deletions

View File

@@ -6,7 +6,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <cassert>
@@ -185,6 +184,18 @@ double strtodouble(const std::string &value) {
}
}
void split_host_port(const std::string &target, std::string &host, std::string &port) {
size_t lastcolon = target.rfind(':');
if (lastcolon == std::string::npos) {
host = ""; port = ""; return;
}
host = target.substr(0, lastcolon);
port = target.substr(lastcolon + 1);
if ((host == "") || (port == "")) {
host = ""; port = ""; return;
}
}
std::string ltrim(std::string s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace))));
@@ -311,6 +322,12 @@ LuaDefine(unittests_util, "c") {
LuaAssert(L, std::isnan(util::strtodouble("12ab")));
LuaAssert(L, std::isnan(util::strtodouble("")));
// Test split_host_port
std::string host, port;
util::split_host_port("stanford.edu:80", host, port);
LuaAssertStrEq(L, host, "stanford.edu");
LuaAssertStrEq(L, port, "80");
// Test trim, ltrim, rtrim
LuaAssert(L, util::ltrim(" foo ") == "foo ");
LuaAssert(L, util::rtrim(" foo ") == " foo");