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
#include <string>
#include <spdlog/common.h>
namespace spdlog {
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())
return;
@ -16,11 +17,12 @@ inline void scramble(std::string& dst, std::string_view s)
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));
++cursor;
start = cursor;
dst.append(with);
// dst.append(with);
dst.append(with.data(), with.size());
};
while (cursor != end) {

@ -1,9 +1,9 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include "attr_composer.h"
#include <spdlog/common.h>
namespace spdlog {
namespace details {
@ -17,28 +17,31 @@ struct attr
std::string value;
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?
scramble(key, *l.begin());
scramble(value, *(l.begin()+1));
}
attr(std::string_view k, bool v)
: key{k}
, value{v ? "true" : "false"}
{}
attr(string_view_t k, bool v)
: value{v ? "true" : "false"}
{
key = std::string{k.data(), k.size()};
}
attr(std::string_view k, std::string_view v)
: key{k}
, value{v}
{}
attr(string_view_t k, string_view_t v)
{
key = std::string{k.data(), k.size()};
value = std::string{v.data(), v.size()};
}
template <typename T>
attr(std::string_view k, T const &v)
: key{k}
, value{std::to_string(v)}
{}
attr(string_view_t k, T const &v)
: value{std::to_string(v)}
{
key = std::string{k.data(), k.size()};
}
};
} // namespace details

@ -474,6 +474,8 @@ template <typename Char> class basic_string_view {
/** Returns the string 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 end() const noexcept -> iterator { return data_ + size_; }

Loading…
Cancel
Save