diff --git a/libabyss/src/server.cpp b/libabyss/src/server.cpp index 5a982c9ee..fa85dee1c 100644 --- a/libabyss/src/server.cpp +++ b/libabyss/src/server.cpp @@ -89,12 +89,12 @@ namespace abyss auto idx = line.find_first_of(' '); if(idx == string_view::npos) return false; - Header.Method = line.substr(0, idx); + Header.Method = std::string(line.substr(0, idx)); line = line.substr(idx + 1); idx = line.find_first_of(' '); if(idx == string_view::npos) return false; - Header.Path = line.substr(0, idx); + Header.Path = std::string(line.substr(0, idx)); m_State = eReadHTTPHeaders; return true; } diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 4a45b358d..b8618c19d 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -36,7 +36,7 @@ target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../inc # cut back on fluff if (NOT WIN32) - target_link_libraries(${UTIL_LIB} PUBLIC absl::optional absl::variant cppbackport) + target_link_libraries(${UTIL_LIB} PUBLIC absl::optional absl::variant absl::strings absl::hash cppbackport) endif(NOT WIN32) if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") diff --git a/llarp/service/config.cpp b/llarp/service/config.cpp index 4c0468671..379f522e7 100644 --- a/llarp/service/config.cpp +++ b/llarp/service/config.cpp @@ -15,7 +15,7 @@ namespace llarp parser.IterAll([&](const llarp::ConfigParser::String_t& name, const llarp::ConfigParser::Section_t& section) { llarp::service::Config::section_t values; - values.first = name; + values.first.assign(name.begin(), name.end()); for(const auto& item : section) values.second.emplace_back(item.first, item.second); services.emplace_back(values); diff --git a/llarp/util/ini.hpp b/llarp/util/ini.hpp index 46f5b5b50..c1488426a 100644 --- a/llarp/util/ini.hpp +++ b/llarp/util/ini.hpp @@ -10,9 +10,11 @@ namespace llarp { struct ConfigParser { - using String_t = llarp::string_view; - using Section_t = std::unordered_multimap< String_t, String_t >; - using Config_impl_t = std::unordered_map< String_t, Section_t >; + using String_t = llarp::string_view; + using Section_t = + std::unordered_multimap< String_t, String_t, string_view_hash >; + using Config_impl_t = + std::unordered_map< String_t, Section_t, string_view_hash >; /// clear parser void Clear(); diff --git a/llarp/util/json.hpp b/llarp/util/json.hpp index 0bfa1b2e9..1c6e84f76 100644 --- a/llarp/util/json.hpp +++ b/llarp/util/json.hpp @@ -1,6 +1,8 @@ #ifndef LLARP_UTIL_JSON_HPP #define LLARP_UTIL_JSON_HPP +#include + #include #include @@ -79,11 +81,6 @@ namespace llarp using Writer = rapidjson::Writer< Stream >; } // namespace json -#if __cplusplus >= 201703L - using string_view = std::string_view; -#else - using string_view = std::string; -#endif namespace json { struct IParser diff --git a/llarp/util/string_view.hpp b/llarp/util/string_view.hpp index 5146664a4..9c6663ba9 100644 --- a/llarp/util/string_view.hpp +++ b/llarp/util/string_view.hpp @@ -6,7 +6,9 @@ #include namespace llarp { - using string_view = std::string_view; + using string_view = std::string_view; + using string_view_hash = std::hash< string_view >; + static std::string string_view_string(const string_view& v) { @@ -14,15 +16,17 @@ namespace llarp } } // namespace llarp #else -#include +#include +#include namespace llarp { - using string_view = std::string; + using string_view = absl::string_view; + using string_view_hash = absl::Hash< string_view >; static std::string string_view_string(const string_view& v) { - return v; + return std::string(v); }; } // namespace llarp #endif diff --git a/test/util/test_llarp_util_ini.cpp b/test/util/test_llarp_util_ini.cpp index 498e9c7d5..ff0373405 100644 --- a/test/util/test_llarp_util_ini.cpp +++ b/test/util/test_llarp_util_ini.cpp @@ -2,11 +2,12 @@ #include -struct TestINIParser : public ::testing::Test -{ +struct TestINIParser : public ::testing::Test +{ llarp::ConfigParser parser; - void TearDown() + void + TearDown() { parser.Clear(); } @@ -21,7 +22,7 @@ TEST_F(TestINIParser, TestParseOneSection) { llarp::ConfigParser::Section_t sect; // this is an anti pattern don't write this kind of code with configpaser - auto assertVisit = [§](const auto & section) -> bool { + auto assertVisit = [§](const auto& section) -> bool { sect = section; return true; }; @@ -34,7 +35,7 @@ TEST_F(TestINIParser, TestParseOneSection) #if __cplusplus >= 201703L ASSERT_STREQ(llarp::string_view_string(itr->second).c_str(), "val"); #else - ASSERT_STREQ(itr->second.c_str(), "val"); + ASSERT_EQ(itr->second, "val"); #endif } @@ -42,7 +43,7 @@ TEST_F(TestINIParser, TestParseSectionDuplicateKeys) { ASSERT_TRUE(parser.LoadString("[test]\nkey1=val1\nkey1=val2")); size_t num = 0; - auto visit =[&num](const auto & section) -> bool { + auto visit = [&num](const auto& section) -> bool { num = section.count("key1"); return true; }; @@ -52,5 +53,7 @@ TEST_F(TestINIParser, TestParseSectionDuplicateKeys) TEST_F(TestINIParser, TestParseInvalid) { - ASSERT_FALSE(parser.LoadString("srged5ghe5\nf34wtge5\nw34tgfs4ygsd5yg=4;\n#g4syhgd5\n")); + ASSERT_FALSE( + parser.LoadString("srged5ghe5\nf34wtge5\nw34tgfs4ygsd5yg=4;\n#" + "g4syhgd5\n")); }