Provide a conversion function from icinga::String to boost::string_view

Boost.Beast changed the signature of
boost::beast::http::basic_fields::set in version 1.74 so that no longer
allows passing an icinga::String instance as value. This adds a
conversion function so that it works again.
This commit is contained in:
Julian Brost 2020-12-22 14:36:48 +01:00
parent 339b37a985
commit eab07a7318
2 changed files with 14 additions and 0 deletions

View File

@ -127,6 +127,18 @@ String::operator const std::string&() const
return m_Data;
}
/**
* Conversion function to boost::string_view.
*
* This allows using String as the value for HTTP headers in boost::beast::http::basic_fields::set.
*
* @return A boost::string_view representing this string.
*/
String::operator boost::string_view() const
{
return boost::string_view(m_Data);
}
const char *String::CStr() const
{
return m_Data.c_str();

View File

@ -6,6 +6,7 @@
#include "base/i2-base.hpp"
#include "base/object.hpp"
#include <boost/range/iterator.hpp>
#include <boost/utility/string_view.hpp>
#include <string>
#include <iosfwd>
@ -71,6 +72,7 @@ public:
bool operator<(const String& rhs) const;
operator const std::string&() const;
operator boost::string_view() const;
const char *CStr() const;