#include <vector>
#include <algorithm>
-#ifdef __cpp_lib_string_view
using std::string_view;
-#else
-#include <boost/version.hpp>
-#if BOOST_VERSION >= 106100
-#include <boost/utility/string_view.hpp>
-using boost::string_view;
-#elif BOOST_VERSION >= 105300
-#include <boost/utility/string_ref.hpp>
-using string_view = boost::string_ref;
-#else
-using string_view = std::string;
-#endif
-#endif
-
/* open issues:
*
#pragma once
-#ifdef __cpp_lib_string_view
using pdns_string_view = std::string_view;
-#else
-#include <boost/version.hpp>
-#if BOOST_VERSION >= 106400
-// string_view already exists in 1.61.0 but string_view::at() is not usable with modern compilers, see:
-// https://github.com/boostorg/utility/pull/26
-#include <boost/utility/string_view.hpp>
-using pdns_string_view = boost::string_view;
-#elif BOOST_VERSION >= 105300
-#include <boost/utility/string_ref.hpp>
-using pdns_string_view = boost::string_ref;
-#else
-
-/* this class implements a very restricted view, since nothing else is available
- and doing a full allocation + copy is just dumb */
-class pdns_string_view
-{
-public:
- pdns_string_view() noexcept
- {
- }
-
- pdns_string_view(const std::string& str) noexcept: d_ptr{str.data()}, d_size(str.size())
- {
- }
-
- pdns_string_view(const char* str, size_t len) noexcept: d_ptr{str}, d_size(len)
- {
- }
-
- size_t size() const noexcept
- {
- return d_size;
- }
-
- const char& at(size_t pos) const
- {
- if (pos >= d_size) {
- throw std::out_of_range("pdns_string_view::at() " + std::to_string(pos) + " >= " + std::to_string(d_size));
- }
- return *(d_ptr + pos);
- }
-
- const char* data() const noexcept
- {
- return d_ptr;
- }
-
-private:
- const char* d_ptr{nullptr};
- const size_t d_size{0};
-};
-
-#endif
-#endif