C++11 backwards compat fixes by replacing std::string_view with built-in string_view_t

pull/2687/head
Bailey Chittle 3 years ago
parent 10d144f3e9
commit 89d53711a1

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <string> #include <string>
#include <spdlog/common.h>
namespace spdlog { namespace spdlog {
namespace details { namespace details {
inline void scramble(std::string& dst, std::string_view s) inline void scramble(std::string& dst, string_view_t s)
{ {
if (s.empty()) if (s.empty())
return; return;
@ -16,11 +17,12 @@ inline void scramble(std::string& dst, std::string_view s)
dst.reserve(dst.size() + s.size()); dst.reserve(dst.size() + s.size());
auto replace = [&](std::string_view with) { auto replace = [&](string_view_t with) {
dst.append(start, size_t(cursor - start)); dst.append(start, size_t(cursor - start));
++cursor; ++cursor;
start = cursor; start = cursor;
dst.append(with); // dst.append(with);
dst.append(with.data(), with.size());
}; };
while (cursor != end) { while (cursor != end) {

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include "attr_composer.h" #include "attr_composer.h"
#include <spdlog/common.h>
namespace spdlog { namespace spdlog {
namespace details { namespace details {
@ -17,28 +17,31 @@ struct attr
std::string value; std::string value;
public: public:
attr(std::initializer_list<std::string_view> l) { attr(std::initializer_list<string_view_t> l) {
if (l.size() != 2) return; // throw exception if not kv pair? if (l.size() != 2) return; // throw exception if not kv pair?
scramble(key, *l.begin()); scramble(key, *l.begin());
scramble(value, *(l.begin()+1)); scramble(value, *(l.begin()+1));
} }
attr(std::string_view k, bool v) attr(string_view_t k, bool v)
: key{k} : value{v ? "true" : "false"}
, value{v ? "true" : "false"} {
{} key = std::string{k.data(), k.size()};
}
attr(std::string_view k, std::string_view v) attr(string_view_t k, string_view_t v)
: key{k} {
, value{v} key = std::string{k.data(), k.size()};
{} value = std::string{v.data(), v.size()};
}
template <typename T> template <typename T>
attr(std::string_view k, T const &v) attr(string_view_t k, T const &v)
: key{k} : value{std::to_string(v)}
, value{std::to_string(v)} {
{} key = std::string{k.data(), k.size()};
}
}; };
} // namespace details } // namespace details

@ -474,6 +474,8 @@ template <typename Char> class basic_string_view {
/** Returns the string size. */ /** Returns the string size. */
constexpr auto size() const noexcept -> size_t { return size_; } constexpr auto size() const noexcept -> size_t { return size_; }
constexpr auto empty() const noexcept -> bool { return size_ == 0; }
constexpr auto begin() const noexcept -> iterator { return data_; } constexpr auto begin() const noexcept -> iterator { return data_; }
constexpr auto end() const noexcept -> iterator { return data_ + size_; } constexpr auto end() const noexcept -> iterator { return data_ + size_; }

Loading…
Cancel
Save