2022-02-17 20:02:08 -05:00
|
|
|
|
2022-02-23 23:08:28 -05:00
|
|
|
#include "wrap-string.hpp"
|
2022-02-24 02:17:41 -05:00
|
|
|
#include "wrap-string-view.hpp"
|
2022-02-23 23:08:28 -05:00
|
|
|
#include "wrap-vector.hpp"
|
|
|
|
|
|
2022-02-17 20:02:08 -05:00
|
|
|
#include "driver-util.hpp"
|
|
|
|
|
#include "luastack.hpp"
|
2022-02-18 03:59:21 -05:00
|
|
|
#include "util.hpp"
|
2022-02-17 20:02:08 -05:00
|
|
|
|
|
|
|
|
namespace drv {
|
|
|
|
|
|
2022-02-24 02:17:41 -05:00
|
|
|
void split_host_port(drv::string_view target, drv::string &host, drv::string &port) {
|
2022-02-17 20:02:08 -05:00
|
|
|
size_t lastcolon = target.rfind(':');
|
2022-02-24 02:17:41 -05:00
|
|
|
if (lastcolon == drv::string_view::npos) {
|
2022-02-17 20:02:08 -05:00
|
|
|
host = ""; port = ""; return;
|
|
|
|
|
}
|
|
|
|
|
host = target.substr(0, lastcolon);
|
|
|
|
|
port = target.substr(lastcolon + 1);
|
|
|
|
|
if ((host == "") || (port == "")) {
|
|
|
|
|
host = ""; port = ""; return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 02:17:41 -05:00
|
|
|
drv::vector<drv::string> parse_control_lst(drv::string_view ctrl) {
|
|
|
|
|
drv::vector<drv::string> result;
|
2022-02-18 03:59:21 -05:00
|
|
|
while (!ctrl.empty()) {
|
2022-02-24 02:17:41 -05:00
|
|
|
drv::string_view line = util::sv_read_line(ctrl);
|
|
|
|
|
drv::string_view trimmed = util::sv_trim(line);
|
2022-02-18 03:59:21 -05:00
|
|
|
if ((trimmed.size() > 0) && (trimmed[0] != '#')) {
|
|
|
|
|
result.emplace_back(trimmed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-02-17 20:02:08 -05:00
|
|
|
} // namespace drv
|
|
|
|
|
|
|
|
|
|
LuaDefine(unittests_driverutil, "", "some unit tests") {
|
|
|
|
|
// Test split_host_port
|
2022-02-24 02:17:41 -05:00
|
|
|
drv::string host, port;
|
2022-02-17 20:02:08 -05:00
|
|
|
drv::split_host_port("stanford.edu:80", host, port);
|
|
|
|
|
LuaAssertStrEq(L, host, "stanford.edu");
|
|
|
|
|
LuaAssertStrEq(L, port, "80");
|
2022-02-18 03:59:21 -05:00
|
|
|
|
2022-02-17 20:02:08 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
2022-02-18 03:59:21 -05:00
|
|
|
|