Progress on mingw driver
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user