mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
Merge pull request #348 from michael-loki/string_view_abseil
Use string_view for string_view
This commit is contained in:
commit
9578d10b8b
@ -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;
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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);
|
||||
|
@ -11,8 +11,10 @@ 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 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();
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef LLARP_UTIL_JSON_HPP
|
||||
#define LLARP_UTIL_JSON_HPP
|
||||
|
||||
#include <util/string_view.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
@ -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
|
||||
|
@ -7,6 +7,8 @@
|
||||
namespace llarp
|
||||
{
|
||||
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 <string>
|
||||
#include <absl/hash/hash.h>
|
||||
#include <absl/strings/string_view.h>
|
||||
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
|
||||
|
@ -6,7 +6,8 @@ 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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user