diff --git a/include/opendht/value.h b/include/opendht/value.h index b7d9f010465bbfcfe59674a4a2cac86eee578adb..5539ee8756fef15773ffea07b985e82d2a75a0cc 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -27,6 +27,7 @@ #include <msgpack.hpp> #include <string> +#include <string_view> #include <sstream> #include <bitset> #include <vector> @@ -741,7 +742,7 @@ private: struct OPENDHT_PUBLIC Select { Select() { } - Select(const std::string& q_str); + Select(std::string_view q_str); bool isSatisfiedBy(const Select& os) const; @@ -796,7 +797,7 @@ private: struct OPENDHT_PUBLIC Where { Where() { } - Where(const std::string& q_str); + Where(std::string_view q_str); bool isSatisfiedBy(const Where& where) const; @@ -936,11 +937,11 @@ struct OPENDHT_PUBLIC Query * - $string$: a simple string WITHOUT SPACES. * - $integer$: a simple integer. */ - Query(std::string q_str) { + Query(std::string_view q_str) { auto pos_W = q_str.find("WHERE"); auto pos_w = q_str.find("where"); - auto pos = std::min(pos_W != std::string::npos ? pos_W : q_str.size(), - pos_w != std::string::npos ? pos_w : q_str.size()); + auto pos = std::min(pos_W != std::string_view::npos ? pos_W : q_str.size(), + pos_w != std::string_view::npos ? pos_w : q_str.size()); select = q_str.substr(0, pos); where = q_str.substr(pos, q_str.size()-pos); } diff --git a/src/value.cpp b/src/value.cpp index 421668528728511b68b82a1da08ae02037502b9a..6279921923d6a609ed4463711467b274f748f292 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -406,8 +406,8 @@ void trim_str(std::string& str) { str = str.substr(first, last - first + 1); } -Select::Select(const std::string& q_str) { - std::istringstream q_iss {q_str}; +Select::Select(std::string_view q_str) { + std::istringstream q_iss {std::string(q_str)}; std::string token {}; q_iss >> token; @@ -431,8 +431,8 @@ Select::Select(const std::string& q_str) { } } -Where::Where(const std::string& q_str) { - std::istringstream q_iss {q_str}; +Where::Where(std::string_view q_str) { + std::istringstream q_iss {std::string(q_str)}; std::string token {}; q_iss >> token; if (token == "WHERE" or token == "where") {