Get rid of wrap-string-view
This commit is contained in:
@@ -241,7 +241,7 @@ void DrivenEngine::drv_recv_incoming(int chid, int nbytes, const char *bytes) {
|
||||
}
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_notify_close(int chid, eng::string_view err) {
|
||||
void DrivenEngine::drv_notify_close(int chid, std::string_view err) {
|
||||
Channel *ch = get_chid(chid);
|
||||
ch->closed_ = true;
|
||||
ch->error_ = err;
|
||||
@@ -260,7 +260,7 @@ void DrivenEngine::drv_clear_lua_source() {
|
||||
rescan_lua_source_ = false;
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_add_lua_source(eng::string_view fn, eng::string_view data) {
|
||||
void DrivenEngine::drv_add_lua_source(std::string_view fn, std::string_view data) {
|
||||
if (lua_source_ == nullptr) {
|
||||
lua_source_.reset(new util::LuaSourceVec);
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public:
|
||||
// delete it. Closing a channel prevents it from showing up in
|
||||
// 'drv_list_channels'.
|
||||
//
|
||||
void drv_notify_close(int chid, eng::string_view err);
|
||||
void drv_notify_close(int chid, std::string_view err);
|
||||
|
||||
// Notify the DrivenEngine that somebody connected to an incoming port.
|
||||
// This will cause the DrivenEngine to allocate a new channel and put the
|
||||
@@ -361,7 +361,7 @@ public:
|
||||
// Set the lua source code. The driver is expected to read the lua source
|
||||
// code and store it (using this function) once before invoking
|
||||
//
|
||||
void drv_add_lua_source(eng::string_view fn, eng::string_view data);
|
||||
void drv_add_lua_source(std::string_view fn, std::string_view data);
|
||||
|
||||
// Invoke the init or update event.
|
||||
//
|
||||
|
||||
@@ -37,30 +37,30 @@ static void if_error_print_and_exit(const drv::string &str) {
|
||||
}
|
||||
}
|
||||
|
||||
static drv::string_view read_file(const char *fn, char *buf, int bufsize, drv::string &err) {
|
||||
static std::string_view read_file(const char *fn, char *buf, int bufsize, drv::string &err) {
|
||||
FILE *f = fopen(fn, "r");
|
||||
if (f == 0) {
|
||||
err = drv::string("cannot read file") + fn;
|
||||
buf[0] = 0;
|
||||
return drv::string_view(buf, 0);
|
||||
return std::string_view(buf, 0);
|
||||
}
|
||||
int nread = fread(buf, 1, bufsize, f);
|
||||
if (nread < 0) {
|
||||
err = drv::string("cannot read file: ") + fn;
|
||||
buf[0] = 0;
|
||||
return drv::string_view(buf, 0);
|
||||
return std::string_view(buf, 0);
|
||||
}
|
||||
if (nread == bufsize) {
|
||||
err = drv::string("file too large: ") + fn;
|
||||
buf[0] = 0;
|
||||
return drv::string_view(buf, 0);
|
||||
return std::string_view(buf, 0);
|
||||
}
|
||||
err = "";
|
||||
return drv::string_view(buf, nread);
|
||||
return std::string_view(buf, nread);
|
||||
}
|
||||
|
||||
|
||||
static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, drv::string_view require_cert) {
|
||||
static SSL_CTX *new_ssl_context(bool server_cert, bool root_certs, std::string_view require_cert) {
|
||||
SSL_CTX *ctx = SSL_CTX_new(TLS_method());
|
||||
SSL_CTX_set_mode(ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||
SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE);
|
||||
@@ -158,20 +158,20 @@ public:
|
||||
void handle_lua_source() {
|
||||
if (driven_->drv_get_rescan_lua_source()) {
|
||||
drv::string err;
|
||||
drv::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err);
|
||||
std::string_view ctrl = read_file("lua/control.lst", chbuf.get(), CHBUF_SIZE, err);
|
||||
if_error_print_and_exit(err);
|
||||
drv::vector<drv::string> names = drv::parse_control_lst(ctrl);
|
||||
driven_->drv_clear_lua_source();
|
||||
for (const drv::string &str : names) {
|
||||
drv::string lfn = drv::string("lua/") + str;
|
||||
drv::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err);
|
||||
std::string_view data = read_file(lfn.c_str(), chbuf.get(), CHBUF_SIZE, err);
|
||||
if_error_print_and_exit(err);
|
||||
driven_->drv_add_lua_source(str, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close_channel(ChanInfo &chan, drv::string_view err) {
|
||||
void close_channel(ChanInfo &chan, std::string_view err) {
|
||||
// std::cerr << "Closing channel " << chan.chid << std::endl;
|
||||
assert(chan.state != CHAN_INACTIVE);
|
||||
// Close and release the SSL channel.
|
||||
|
||||
@@ -73,7 +73,7 @@ static void enable_tty_raw() {
|
||||
assert(status >= 0);
|
||||
}
|
||||
|
||||
static SOCKET open_connection(drv::string_view target, drv::string &err) {
|
||||
static SOCKET open_connection(std::string_view target, drv::string &err) {
|
||||
struct addrinfo *addrs = nullptr;
|
||||
struct addrinfo *goodaddr = nullptr;
|
||||
struct addrinfo hints;
|
||||
|
||||
@@ -59,11 +59,11 @@ static PADDRINFOA find_good_addr(PADDRINFOA addrinfo) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SOCKET open_connection(drv::string_view target, drv::string &err) {
|
||||
static SOCKET open_connection(std::string_view target, drv::string &err) {
|
||||
PADDRINFOA addrs = nullptr;
|
||||
PADDRINFOA goodaddr = nullptr;
|
||||
SOCKET sock = INVALID_SOCKET;
|
||||
drv::string_view host, port;
|
||||
std::string_view host, port;
|
||||
|
||||
err.clear();
|
||||
util::split_host_port(target, host, port);
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-string-view.hpp"
|
||||
#include "wrap-vector.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "driver-util.hpp"
|
||||
#include "luastack.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
|
||||
namespace drv {
|
||||
|
||||
void split_host_port(drv::string_view target, drv::string &host, drv::string &port) {
|
||||
void split_host_port(std::string_view target, drv::string &host, drv::string &port) {
|
||||
size_t lastcolon = target.rfind(':');
|
||||
if (lastcolon == drv::string_view::npos) {
|
||||
if (lastcolon == std::string_view::npos) {
|
||||
host = ""; port = ""; return;
|
||||
}
|
||||
host = target.substr(0, lastcolon);
|
||||
@@ -21,11 +23,11 @@ void split_host_port(drv::string_view target, drv::string &host, drv::string &po
|
||||
}
|
||||
}
|
||||
|
||||
drv::vector<drv::string> parse_control_lst(drv::string_view ctrl) {
|
||||
drv::vector<drv::string> parse_control_lst(std::string_view ctrl) {
|
||||
drv::vector<drv::string> result;
|
||||
while (!ctrl.empty()) {
|
||||
drv::string_view line = util::sv_read_line(ctrl);
|
||||
drv::string_view trimmed = util::sv_trim(line);
|
||||
std::string_view line = util::sv_read_line(ctrl);
|
||||
std::string_view trimmed = util::sv_trim(line);
|
||||
if ((trimmed.size() > 0) && (trimmed[0] != '#')) {
|
||||
result.emplace_back(trimmed);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
#define DRIVER_UTIL_HPP
|
||||
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-string-view.hpp"
|
||||
#include "wrap-vector.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace drv {
|
||||
|
||||
void split_host_port(drv::string_view target, drv::string &host, drv::string &port);
|
||||
void split_host_port(std::string_view target, drv::string &host, drv::string &port);
|
||||
|
||||
drv::vector<drv::string> parse_control_lst(drv::string_view ctrl);
|
||||
drv::vector<drv::string> parse_control_lst(std::string_view ctrl);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -271,25 +271,25 @@ double strtodouble(const eng::string &value) {
|
||||
}
|
||||
}
|
||||
|
||||
eng::string_view sv_ltrim(eng::string_view v) {
|
||||
std::string_view sv_ltrim(std::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(b[0]))) {
|
||||
b++;
|
||||
}
|
||||
return eng::string_view(b, e-b);
|
||||
return std::string_view(b, e-b);
|
||||
}
|
||||
|
||||
eng::string_view sv_rtrim(eng::string_view v) {
|
||||
std::string_view sv_rtrim(std::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(e[-1]))) {
|
||||
e--;
|
||||
}
|
||||
return eng::string_view(b, e-b);
|
||||
return std::string_view(b, e-b);
|
||||
}
|
||||
|
||||
eng::string_view sv_trim(eng::string_view v) {
|
||||
std::string_view sv_trim(std::string_view v) {
|
||||
const char *b = v.data();
|
||||
const char *e = v.data() + v.size();
|
||||
while ((e > b) && (std::isspace(b[0]))) {
|
||||
@@ -298,25 +298,25 @@ eng::string_view sv_trim(eng::string_view v) {
|
||||
while ((e > b) && (std::isspace(e[-1]))) {
|
||||
e--;
|
||||
}
|
||||
return eng::string_view(b, e-b);
|
||||
return std::string_view(b, e-b);
|
||||
}
|
||||
|
||||
eng::string ltrim(eng::string_view v) {
|
||||
eng::string ltrim(std::string_view v) {
|
||||
return eng::string(sv_ltrim(v));
|
||||
}
|
||||
|
||||
eng::string rtrim(eng::string_view v) {
|
||||
eng::string rtrim(std::string_view v) {
|
||||
return eng::string(sv_rtrim(v));
|
||||
}
|
||||
|
||||
eng::string trim(eng::string_view v) {
|
||||
eng::string trim(std::string_view v) {
|
||||
return eng::string(sv_trim(v));
|
||||
}
|
||||
|
||||
eng::string_view sv_read_line(eng::string_view &source) {
|
||||
std::string_view sv_read_line(std::string_view &source) {
|
||||
size_t pos = source.find('\n');
|
||||
eng::string_view result;
|
||||
if (pos == eng::string_view::npos) {
|
||||
std::string_view result;
|
||||
if (pos == std::string_view::npos) {
|
||||
result = source;
|
||||
source = "";
|
||||
} else {
|
||||
@@ -449,10 +449,10 @@ LuaDefine(unittests_util, "", "some unit tests") {
|
||||
LuaAssert(L, util::trim("") == "");
|
||||
|
||||
// Test sv_read_line
|
||||
eng::string_view v = "foo\nbar\r\n";
|
||||
eng::string_view v1 = util::sv_read_line(v);
|
||||
eng::string_view v2 = util::sv_read_line(v);
|
||||
eng::string_view v3 = util::sv_read_line(v);
|
||||
std::string_view v = "foo\nbar\r\n";
|
||||
std::string_view v1 = util::sv_read_line(v);
|
||||
std::string_view v2 = util::sv_read_line(v);
|
||||
std::string_view v3 = util::sv_read_line(v);
|
||||
LuaAssertStrEq(L, v1, "foo");
|
||||
LuaAssertStrEq(L, v2, "bar");
|
||||
LuaAssertStrEq(L, v3, "");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define UTIL_HPP
|
||||
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-string-view.hpp"
|
||||
#include "wrap-set.hpp"
|
||||
#include "wrap-map.hpp"
|
||||
#include "wrap-algorithm.hpp"
|
||||
@@ -11,6 +10,8 @@
|
||||
#include "wrap-memory.hpp"
|
||||
#include "wrap-utility.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "luastack.hpp"
|
||||
#include "spookyv2.hpp"
|
||||
|
||||
@@ -101,17 +102,17 @@ int64_t strtoint(const eng::string &value, int64_t errval);
|
||||
double strtodouble(const eng::string &value);
|
||||
|
||||
// Trim a string_view
|
||||
eng::string_view sv_ltrim(eng::string_view v);
|
||||
eng::string_view sv_rtrim(eng::string_view v);
|
||||
eng::string_view sv_trim(eng::string_view v);
|
||||
std::string_view sv_ltrim(std::string_view v);
|
||||
std::string_view sv_rtrim(std::string_view v);
|
||||
std::string_view sv_trim(std::string_view v);
|
||||
|
||||
// Trim strings: left end, right end, both ends.
|
||||
eng::string ltrim(eng::string_view s);
|
||||
eng::string rtrim(eng::string_view s);
|
||||
eng::string trim(eng::string_view s);
|
||||
eng::string ltrim(std::string_view s);
|
||||
eng::string rtrim(std::string_view s);
|
||||
eng::string trim(std::string_view s);
|
||||
|
||||
// Read a line from a string_view
|
||||
eng::string_view sv_read_line(eng::string_view &source);
|
||||
std::string_view sv_read_line(std::string_view &source);
|
||||
|
||||
// Calculate distance between two points
|
||||
double distance_squared(double x1, double y1, double x2, double y2);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef WRAP_STRING_VIEW_HPP
|
||||
#define WRAP_STRING_VIEW_HPP
|
||||
|
||||
#include "two-mallocs.hpp"
|
||||
#include <string_view>
|
||||
|
||||
namespace eng {
|
||||
template<class C, class T=std::char_traits<C>>
|
||||
using basic_string_view = std::basic_string_view<C, T>;
|
||||
using string_view = basic_string_view<char>;
|
||||
} // namespace eng
|
||||
|
||||
namespace drv {
|
||||
template<class C, class T=std::char_traits<C>>
|
||||
using basic_string_view = std::basic_string_view<C, T>;
|
||||
using string_view = basic_string_view<char>;
|
||||
} // namespace drv
|
||||
|
||||
#endif // WRAP_STRING_VIEW_HPP
|
||||
Reference in New Issue
Block a user