Use beast::string_view alias

This commit is contained in:
Vinnie Falco
2017-05-05 14:45:15 -07:00
parent f50a37b778
commit 84ece031f2
36 changed files with 319 additions and 288 deletions

View File

@ -1,5 +1,7 @@
1.0.0-b39 1.0.0-b39
* Use beast::string_view alias
WebSocket: WebSocket:
* Add websocket async echo ssl server test: * Add websocket async echo ssl server test:

View File

@ -168,6 +168,7 @@
<member><link linkend="beast.ref.static_buffer">static_buffer</link></member> <member><link linkend="beast.ref.static_buffer">static_buffer</link></member>
<member><link linkend="beast.ref.static_buffer_n">static_buffer_n</link></member> <member><link linkend="beast.ref.static_buffer_n">static_buffer_n</link></member>
<member><link linkend="beast.ref.static_string">static_string</link></member> <member><link linkend="beast.ref.static_string">static_string</link></member>
<member><link linkend="beast.ref.string_view">string_view</link></member>
<member><link linkend="beast.ref.system_error">system_error</link></member> <member><link linkend="beast.ref.system_error">system_error</link></member>
</simplelist> </simplelist>
</entry> </entry>

View File

@ -8,8 +8,8 @@
#ifndef BEAST_DETAIL_CI_CHAR_TRAITS_HPP #ifndef BEAST_DETAIL_CI_CHAR_TRAITS_HPP
#define BEAST_DETAIL_CI_CHAR_TRAITS_HPP #define BEAST_DETAIL_CI_CHAR_TRAITS_HPP
#include <beast/core/string_view.hpp>
#include <boost/range/algorithm/equal.hpp> #include <boost/range/algorithm/equal.hpp>
#include <boost/utility/string_ref.hpp>
namespace beast { namespace beast {
namespace detail { namespace detail {
@ -42,10 +42,10 @@ tolower(signed char c)
template<std::size_t N> template<std::size_t N>
inline inline
boost::string_ref string_view
string_helper(const char (&s)[N]) string_helper(const char (&s)[N])
{ {
return boost::string_ref{s, N-1}; return string_view{s, N-1};
} }
template<class T> template<class T>

View File

@ -8,7 +8,7 @@
#ifndef BEAST_DETAIL_STATIC_STRING_HPP #ifndef BEAST_DETAIL_STATIC_STRING_HPP
#define BEAST_DETAIL_STATIC_STRING_HPP #define BEAST_DETAIL_STATIC_STRING_HPP
#include <boost/utility/string_ref.hpp> #include <beast/core/string_view.hpp>
#include <iterator> #include <iterator>
#include <type_traits> #include <type_traits>

View File

@ -95,7 +95,7 @@ static_string(std::initializer_list<CharT> init)
template<std::size_t N, class CharT, class Traits> template<std::size_t N, class CharT, class Traits>
static_string<N, CharT, Traits>:: static_string<N, CharT, Traits>::
static_string(boost::basic_string_ref<CharT, Traits> sv) static_string(string_view_type sv)
{ {
assign(sv); assign(sv);
} }
@ -188,12 +188,10 @@ template<class T>
auto auto
static_string<N, CharT, Traits>:: static_string<N, CharT, Traits>::
assign(T const& t, size_type pos, size_type count) -> assign(T const& t, size_type pos, size_type count) ->
typename std::enable_if< typename std::enable_if<std::is_convertible<T,
std::is_convertible<T, boost::basic_string_ref< string_view_type>::value, static_string&>::type
CharT, Traits>>::value, static_string&>::type
{ {
auto const sv = boost::basic_string_ref< auto const sv = string_view_type(t).substr(pos, count);
CharT, Traits>(t).substr(pos, count);
if(sv.size() > max_size()) if(sv.size() > max_size())
throw detail::make_exception<std::length_error>( throw detail::make_exception<std::length_error>(
"sv.size() > max_size()", __FILE__, __LINE__); "sv.size() > max_size()", __FILE__, __LINE__);
@ -352,14 +350,13 @@ auto
static_string<N, CharT, Traits>:: static_string<N, CharT, Traits>::
insert(size_type index, const T& t, insert(size_type index, const T& t,
size_type index_str, size_type count) -> size_type index_str, size_type count) ->
typename std::enable_if< typename std::enable_if<std::is_convertible<
std::is_convertible<T const&, T const&, string_view_type>::value &&
boost::basic_string_ref<CharT, Traits>>::value &&
! std::is_convertible<T const&, CharT const*>::value, ! std::is_convertible<T const&, CharT const*>::value,
static_string&>::type static_string&>::type
{ {
auto const str = boost::basic_string_ref< auto const str =
CharT, Traits>(t).substr(index_str, count); string_view_type(t).substr(index_str, count);
return insert(index, str.data(), str.size()); return insert(index, str.data(), str.size());
} }
@ -424,16 +421,17 @@ append(static_string<M, CharT, Traits> const& str,
if(pos >= str.size()) if(pos >= str.size())
throw detail::make_exception<std::out_of_range>( throw detail::make_exception<std::out_of_range>(
"pos > str.size()", __FILE__, __LINE__); "pos > str.size()", __FILE__, __LINE__);
boost::basic_string_ref<CharT, Traits> const ss{ string_view_type const ss{&str.s_[pos],
&str.s_[pos], (std::min)(count, str.size() - pos)}; (std::min)(count, str.size() - pos)};
insert(size(), ss.data(), ss.size()); insert(size(), ss.data(), ss.size());
return *this; return *this;
} }
template<std::size_t N, class CharT, class Traits> template<std::size_t N, class CharT, class Traits>
boost::basic_string_ref<CharT, Traits> auto
static_string<N, CharT, Traits>:: static_string<N, CharT, Traits>::
substr(size_type pos, size_type count) const substr(size_type pos, size_type count) const ->
string_view_type
{ {
if(pos > size()) if(pos > size())
throw detail::make_exception<std::out_of_range>( throw detail::make_exception<std::out_of_range>(

View File

@ -9,8 +9,8 @@
#define BEAST_STATIC_STRING_HPP #define BEAST_STATIC_STRING_HPP
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/static_string.hpp> #include <beast/core/detail/static_string.hpp>
#include <boost/utility/string_ref.hpp>
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <initializer_list> #include <initializer_list>
@ -70,6 +70,10 @@ public:
using const_reverse_iterator = using const_reverse_iterator =
std::reverse_iterator<const_iterator>; std::reverse_iterator<const_iterator>;
/// The type of `string_view` returned by the interface
using string_view_type =
beast::basic_string_view<CharT, Traits>;
// //
// Constants // Constants
// //
@ -123,23 +127,21 @@ public:
/// Construct from an initializer list /// Construct from an initializer list
static_string(std::initializer_list<CharT> init); static_string(std::initializer_list<CharT> init);
/// Construct from a `basic_string_ref` /// Construct from a `string_view`
explicit explicit
static_string(boost::basic_string_ref<CharT, Traits> sv); static_string(string_view_type sv);
/** Construct from any object convertible to `basic_string_ref`. /** Construct from any object convertible to `string_view_type`.
The range (pos, n) is extracted from the value The range (pos, n) is extracted from the value
obtained by converting `t` to `basic_string_ref`, obtained by converting `t` to `string_view_type`,
and used to construct the string. and used to construct the string.
*/ */
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
template<class T> template<class T>
#else #else
template<class T, template<class T, class = typename std::enable_if<
class = typename std::enable_if< std::is_convertible<T, string_view_type>::value>::type>
std::is_convertible<T, boost::basic_string_ref<
CharT, Traits>> ::value>::type>
#endif #endif
static_string(T const& t, size_type pos, size_type n); static_string(T const& t, size_type pos, size_type n);
@ -184,9 +186,9 @@ public:
return assign(init); return assign(init);
} }
/// Assign from `basic_string_ref`. /// Assign from `string_view_type`.
static_string& static_string&
operator=(boost::basic_string_ref<CharT, Traits> sv) operator=(string_view_type sv)
{ {
return assign(sv); return assign(sv);
} }
@ -240,26 +242,25 @@ public:
return assign(init.begin(), init.end()); return assign(init.begin(), init.end());
} }
/// Assign from `basic_string_ref`. /// Assign from `string_view_type`.
static_string& static_string&
assign(boost::basic_string_ref<CharT, Traits> str) assign(string_view_type str)
{ {
return assign(str.data(), str.size()); return assign(str.data(), str.size());
} }
/** Assign from any object convertible to `basic_string_ref`. /** Assign from any object convertible to `string_view_type`.
The range (pos, n) is extracted from the value The range (pos, n) is extracted from the value
obtained by converting `t` to `basic_string_ref`, obtained by converting `t` to `string_view_type`,
and used to assign the string. and used to assign the string.
*/ */
template<class T> template<class T>
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
static_string& static_string&
#else #else
typename std::enable_if< typename std::enable_if<std::is_convertible<T,
std::is_convertible<T, boost::basic_string_ref< string_view_type>::value, static_string&>::type
CharT, Traits>>::value, static_string&>::type
#endif #endif
assign(T const& t, assign(T const& t,
size_type pos, size_type count = npos); size_type pos, size_type count = npos);
@ -339,10 +340,8 @@ public:
return data(); return data();
} }
// VFALCO What about boost::string_view? /// Convert a static string to a `string_view_type`
// operator string_view_type() const
/// Convert a static string to a `static_string_ref`
operator boost::basic_string_ref<CharT, Traits>() const
{ {
return boost::basic_string_ref< return boost::basic_string_ref<
CharT, Traits>{data(), size()}; CharT, Traits>{data(), size()};
@ -552,8 +551,7 @@ public:
} }
static_string& static_string&
insert(size_type index, insert(size_type index, string_view_type str)
boost::basic_string_ref<CharT, Traits> str)
{ {
return insert(index, str.data(), str.size()); return insert(index, str.data(), str.size());
} }
@ -563,8 +561,7 @@ public:
static_string& static_string&
#else #else
typename std::enable_if< typename std::enable_if<
std::is_convertible<T const&, std::is_convertible<T const&, string_view_type>::value &&
boost::basic_string_ref<CharT, Traits>>::value &&
! std::is_convertible<T const&, CharT const*>::value, ! std::is_convertible<T const&, CharT const*>::value,
static_string&>::type static_string&>::type
#endif #endif
@ -645,7 +642,7 @@ public:
} }
static_string& static_string&
append(boost::basic_string_ref<CharT, Traits> sv) append(string_view_type sv)
{ {
insert(size(), sv); insert(size(), sv);
return *this; return *this;
@ -653,8 +650,7 @@ public:
template<class T> template<class T>
typename std::enable_if< typename std::enable_if<
std::is_convertible<T const&, std::is_convertible<T const&, string_view_type>::value &&
boost::basic_string_ref<CharT, Traits>>::value &&
! std::is_convertible<T const&, CharT const*>::value, ! std::is_convertible<T const&, CharT const*>::value,
static_string&>::type static_string&>::type
append(T const& t, size_type pos, size_type count = npos) append(T const& t, size_type pos, size_type count = npos)
@ -690,7 +686,7 @@ public:
} }
static_string& static_string&
operator+=(boost::basic_string_ref<CharT, Traits> const& str) operator+=(string_view_type const& str)
{ {
return append(str); return append(str);
} }
@ -746,7 +742,7 @@ public:
} }
int int
compare(boost::basic_string_ref<CharT, Traits> str) const compare(string_view_type str) const
{ {
return detail::lexicographical_compare<CharT, Traits>( return detail::lexicographical_compare<CharT, Traits>(
&s_[0], n_, str.data(), str.size()); &s_[0], n_, str.data(), str.size());
@ -754,7 +750,7 @@ public:
int int
compare(size_type pos1, size_type count1, compare(size_type pos1, size_type count1,
boost::basic_string_ref<CharT, Traits> str) const string_view_type str) const
{ {
return detail::lexicographical_compare<CharT, Traits>( return detail::lexicographical_compare<CharT, Traits>(
substr(pos1, count1), str); substr(pos1, count1), str);
@ -765,8 +761,7 @@ public:
int int
#else #else
typename std::enable_if< typename std::enable_if<
std::is_convertible<T const&, std::is_convertible<T const&, string_view_type>::value &&
boost::basic_string_ref<CharT, Traits>>::value &&
! std::is_convertible<T const&, CharT const*>::value, ! std::is_convertible<T const&, CharT const*>::value,
int>::type int>::type
#endif #endif
@ -775,11 +770,10 @@ public:
size_type count2 = npos) const size_type count2 = npos) const
{ {
return compare(pos1, count1, return compare(pos1, count1,
boost::basic_string_ref< string_view_type(t).substr(pos2, count2));
CharT, Traits>(t).substr(pos2, count2));
} }
boost::basic_string_ref<CharT, Traits> string_view_type
substr(size_type pos = 0, size_type count = npos) const; substr(size_type pos = 0, size_type count = npos) const;
/// Copy a substring (pos, pos+count) to character string pointed to by `dest`. /// Copy a substring (pos, pos+count) to character string pointed to by `dest`.
@ -1101,7 +1095,7 @@ operator<<(std::basic_ostream<CharT, Traits>& os,
static_string<N, CharT, Traits> const& str) static_string<N, CharT, Traits> const& str)
{ {
return os << static_cast< return os << static_cast<
boost::basic_string_ref<CharT, Traits>>(str); beast::basic_string_view<CharT, Traits>>(str);
} }
} // beast } // beast

View File

@ -0,0 +1,25 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_STRING_VIEW_HPP
#define BEAST_STRING_VIEW_HPP
#include <boost/utility/string_ref.hpp>
namespace beast {
/// The type of string_view used by the library
using string_view = boost::string_ref;
/// The type of basic_string_view used by the library
template<class CharT, class Traits>
using basic_string_view =
boost::basic_string_ref<CharT, Traits>;
} // beast
#endif

View File

@ -10,11 +10,11 @@
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/core/error.hpp> #include <beast/core/error.hpp>
#include <beast/core/string_view.hpp>
#include <beast/http/detail/basic_parser.hpp> #include <beast/http/detail/basic_parser.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/utility/string_ref.hpp>
#include <memory> #include <memory>
#include <utility> #include <utility>
@ -93,8 +93,8 @@ enum class parse_state
// //
void void
on_request( on_request(
boost::string_ref const& method, string_view const& method,
boost::string_ref const& target, string_view const& target,
int version, int version,
error_code& ec); error_code& ec);
@ -104,7 +104,7 @@ enum class parse_state
void void
on_response( on_response(
int status, int status,
boost::string_ref const& reason, string_view const& reason,
int version, int version,
error_code& ec); error_code& ec);
@ -112,8 +112,8 @@ enum class parse_state
// //
void void
on_field( on_field(
boost::string_ref const& name, string_view const& name,
boost::string_ref const& value, string_view const& value,
error_code& ec); error_code& ec);
// Called after the header is complete. // Called after the header is complete.
@ -136,7 +136,7 @@ enum class parse_state
// //
void void
on_data( on_data(
boost::string_ref const& s, string_view const& s,
error_code& ec); error_code& ec);
// Called zero or more times to retrieve a mutable // Called zero or more times to retrieve a mutable
@ -165,7 +165,7 @@ enum class parse_state
void void
on_chunk( on_chunk(
std::uint64_t length, // Length of this chunk std::uint64_t length, // Length of this chunk
boost::string_ref const& ext, // The chunk extensions, if any string_view const& ext, // The chunk extensions, if any
error_code& ec); error_code& ec);
// Called once when the message is complete. // Called once when the message is complete.
@ -250,8 +250,8 @@ class basic_parser
std::size_t x_; // scratch variable std::size_t x_; // scratch variable
unsigned f_ = 0; // flags unsigned f_ = 0; // flags
parse_state state_ = parse_state::header; parse_state state_ = parse_state::header;
boost::string_ref ext_; string_view ext_;
boost::string_ref body_; string_view body_;
public: public:
/// Copy constructor (disallowed) /// Copy constructor (disallowed)
@ -454,7 +454,7 @@ public:
buffer's `consume` function may invalidate this return buffer's `consume` function may invalidate this return
value. value.
*/ */
boost::string_ref const& string_view const&
body() const body() const
{ {
// This function not available when isDirect==true // This function not available when isDirect==true
@ -472,7 +472,7 @@ public:
buffer's `consume` function may invalidate this return buffer's `consume` function may invalidate this return
value. value.
*/ */
boost::string_ref const& string_view const&
chunk_extension() const chunk_extension() const
{ {
// This function not available when isDirect==true // This function not available when isDirect==true
@ -567,7 +567,7 @@ private:
} }
template<class ConstBufferSequence> template<class ConstBufferSequence>
boost::string_ref string_view
maybe_flatten( maybe_flatten(
ConstBufferSequence const& buffers); ConstBufferSequence const& buffers);
@ -595,8 +595,8 @@ private:
void void
do_field( do_field(
boost::string_ref const& name, string_view const& name,
boost::string_ref const& value, string_view const& value,
error_code& ec); error_code& ec);
std::size_t std::size_t

View File

@ -8,8 +8,8 @@
#ifndef BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP #ifndef BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP
#define BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP #define BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP
#include <beast/core/string_view.hpp>
#include <beast/core/detail/empty_base_optimization.hpp> #include <beast/core/detail/empty_base_optimization.hpp>
#include <boost/utility/string_ref.hpp>
#include <cstddef> #include <cstddef>
#include <iterator> #include <iterator>
@ -22,7 +22,7 @@ namespace detail {
template<class Policy> template<class Policy>
class basic_parsed_list class basic_parsed_list
{ {
boost::string_ref s_; string_view s_;
public: public:
/// The type of policy this list uses for parsing. /// The type of policy this list uses for parsing.
@ -128,7 +128,7 @@ public:
/// Construct a list from a string /// Construct a list from a string
explicit explicit
basic_parsed_list(boost::string_ref const& s) basic_parsed_list(string_view const& s)
: s_(s) : s_(s)
{ {
} }

View File

@ -8,10 +8,10 @@
#ifndef BEAST_HTTP_DETAIL_BASIC_PARSER_HPP #ifndef BEAST_HTTP_DETAIL_BASIC_PARSER_HPP
#define BEAST_HTTP_DETAIL_BASIC_PARSER_HPP #define BEAST_HTTP_DETAIL_BASIC_PARSER_HPP
#include <beast/core/string_view.hpp>
#include <beast/core/detail/ci_char_traits.hpp> #include <beast/core/detail/ci_char_traits.hpp>
#include <beast/http/error.hpp> #include <beast/http/error.hpp>
#include <beast/http/detail/rfc7230.hpp> #include <beast/http/detail/rfc7230.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/version.hpp> #include <boost/version.hpp>
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -187,7 +187,7 @@ protected:
} }
static static
boost::string_ref string_view
make_string(char const* first, char const* last) make_string(char const* first, char const* last)
{ {
return {first, static_cast< return {first, static_cast<
@ -197,8 +197,8 @@ protected:
template<class = void> template<class = void>
static static
bool bool
strieq(boost::string_ref const& s1, strieq(string_view const& s1,
boost::string_ref const& s2) string_view const& s2)
{ {
if(s1.size() != s2.size()) if(s1.size() != s2.size())
return false; return false;
@ -213,7 +213,7 @@ protected:
template<std::size_t N> template<std::size_t N>
bool bool
strieq(const char (&s1)[N], strieq(const char (&s1)[N],
boost::string_ref const& s2) string_view const& s2)
{ {
return strieq({s1, N-1}, s2); return strieq({s1, N-1}, s2);
} }
@ -272,19 +272,19 @@ protected:
} }
static static
boost::string_ref string_view
parse_method(char const*& it) parse_method(char const*& it)
{ {
auto const first = it; auto const first = it;
while(detail::is_tchar(*it)) while(detail::is_tchar(*it))
++it; ++it;
return {first, static_cast< return {first, static_cast<
boost::string_ref::size_type>( string_view::size_type>(
it - first)}; it - first)};
} }
static static
boost::string_ref string_view
parse_target(char const*& it) parse_target(char const*& it)
{ {
auto const first = it; auto const first = it;
@ -293,19 +293,19 @@ protected:
if(*it != ' ') if(*it != ' ')
return {}; return {};
return {first, static_cast< return {first, static_cast<
boost::string_ref::size_type>( string_view::size_type>(
it - first)}; it - first)};
} }
static static
boost::string_ref string_view
parse_name(char const*& it) parse_name(char const*& it)
{ {
auto const first = it; auto const first = it;
while(to_field_char(*it)) while(to_field_char(*it))
++it; ++it;
return {first, static_cast< return {first, static_cast<
boost::string_ref::size_type>( string_view::size_type>(
it - first)}; it - first)};
} }
@ -352,7 +352,7 @@ protected:
} }
static static
boost::string_ref string_view
parse_reason(char const*& it) parse_reason(char const*& it)
{ {
auto const first = it; auto const first = it;

View File

@ -8,10 +8,10 @@
#ifndef BEAST_HTTP_DETAIL_FIELDS_HPP #ifndef BEAST_HTTP_DETAIL_FIELDS_HPP
#define BEAST_HTTP_DETAIL_FIELDS_HPP #define BEAST_HTTP_DETAIL_FIELDS_HPP
#include <beast/core/string_view.hpp>
#include <beast/core/detail/ci_char_traits.hpp> #include <beast/core/detail/ci_char_traits.hpp>
#include <boost/intrusive/list.hpp> #include <boost/intrusive/list.hpp>
#include <boost/intrusive/set.hpp> #include <boost/intrusive/set.hpp>
#include <boost/utility/string_ref.hpp>
namespace beast { namespace beast {
namespace http { namespace http {
@ -29,20 +29,20 @@ public:
std::string first; std::string first;
std::string second; std::string second;
value_type(boost::string_ref const& name_, value_type(string_view const& name_,
boost::string_ref const& value_) string_view const& value_)
: first(name_) : first(name_)
, second(value_) , second(value_)
{ {
} }
boost::string_ref string_view
name() const name() const
{ {
return first; return first;
} }
boost::string_ref string_view
value() const value() const
{ {
return second; return second;
@ -63,8 +63,8 @@ protected:
{ {
value_type data; value_type data;
element(boost::string_ref const& name, element(string_view const& name,
boost::string_ref const& value) string_view const& value)
: data(name, value) : data(name, value)
{ {
} }

View File

@ -8,7 +8,7 @@
#ifndef BEAST_HTTP_DETAIL_RFC7230_HPP #ifndef BEAST_HTTP_DETAIL_RFC7230_HPP
#define BEAST_HTTP_DETAIL_RFC7230_HPP #define BEAST_HTTP_DETAIL_RFC7230_HPP
#include <boost/utility/string_ref.hpp> #include <beast/core/string_view.hpp>
#include <iterator> #include <iterator>
#include <utility> #include <utility>
@ -328,8 +328,8 @@ skip_token(FwdIt& it, FwdIt const& last)
} }
inline inline
boost::string_ref string_view
trim(boost::string_ref const& s) trim(string_view const& s)
{ {
auto first = s.begin(); auto first = s.begin();
auto last = s.end(); auto last = s.end();
@ -349,12 +349,12 @@ trim(boost::string_ref const& s)
struct param_iter struct param_iter
{ {
using iter_type = boost::string_ref::const_iterator; using iter_type = string_view::const_iterator;
iter_type it; iter_type it;
iter_type first; iter_type first;
iter_type last; iter_type last;
std::pair<boost::string_ref, boost::string_ref> v; std::pair<string_view, string_view> v;
bool bool
empty() const empty() const
@ -455,11 +455,11 @@ increment()
*/ */
struct opt_token_list_policy struct opt_token_list_policy
{ {
using value_type = boost::string_ref; using value_type = string_view;
bool bool
operator()(value_type& v, operator()(value_type& v,
char const*& it, boost::string_ref const& s) const char const*& it, string_view const& s) const
{ {
v = {}; v = {};
auto need_comma = it != s.begin(); auto need_comma = it != s.begin();
@ -485,7 +485,7 @@ struct opt_token_list_policy
if(! detail::is_tchar(*it)) if(! detail::is_tchar(*it))
break; break;
} }
v = boost::string_ref{&*p0, v = string_view{&*p0,
static_cast<std::size_t>(it - p0)}; static_cast<std::size_t>(it - p0)};
return true; return true;
} }

View File

@ -9,10 +9,10 @@
#define BEAST_HTTP_FIELDS_HPP #define BEAST_HTTP_FIELDS_HPP
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/empty_base_optimization.hpp> #include <beast/core/detail/empty_base_optimization.hpp>
#include <beast/http/detail/fields.hpp> #include <beast/http/detail/fields.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/utility/string_ref.hpp>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <memory> #include <memory>
@ -195,14 +195,14 @@ public:
/// Returns `true` if the specified field exists. /// Returns `true` if the specified field exists.
bool bool
exists(boost::string_ref const& name) const exists(string_view const& name) const
{ {
return set_.find(name, less{}) != set_.end(); return set_.find(name, less{}) != set_.end();
} }
/// Returns the number of values for the specified field. /// Returns the number of values for the specified field.
std::size_t std::size_t
count(boost::string_ref const& name) const; count(string_view const& name) const;
/** Returns an iterator to the case-insensitive matching field name. /** Returns an iterator to the case-insensitive matching field name.
@ -210,15 +210,15 @@ public:
first field defined by insertion order is returned. first field defined by insertion order is returned.
*/ */
iterator iterator
find(boost::string_ref const& name) const; find(string_view const& name) const;
/** Returns the value for a case-insensitive matching header, or `""`. /** Returns the value for a case-insensitive matching header, or `""`.
If more than one field with the specified name exists, the If more than one field with the specified name exists, the
first field defined by insertion order is returned. first field defined by insertion order is returned.
*/ */
boost::string_ref const string_view const
operator[](boost::string_ref const& name) const; operator[](string_view const& name) const;
/// Clear the contents of the basic_fields. /// Clear the contents of the basic_fields.
void void
@ -234,7 +234,7 @@ public:
@return The number of fields removed. @return The number of fields removed.
*/ */
std::size_t std::size_t
erase(boost::string_ref const& name); erase(string_view const& name);
/** Insert a field value. /** Insert a field value.
@ -247,7 +247,7 @@ public:
@param value A string holding the value of the field. @param value A string holding the value of the field.
*/ */
void void
insert(boost::string_ref const& name, boost::string_ref value); insert(string_view const& name, string_view value);
/** Insert a field value. /** Insert a field value.
@ -262,8 +262,8 @@ public:
*/ */
template<class T> template<class T>
typename std::enable_if< typename std::enable_if<
! std::is_constructible<boost::string_ref, T>::value>::type ! std::is_constructible<string_view, T>::value>::type
insert(boost::string_ref name, T const& value) insert(string_view name, T const& value)
{ {
insert(name, boost::lexical_cast<std::string>(value)); insert(name, boost::lexical_cast<std::string>(value));
} }
@ -278,7 +278,7 @@ public:
@param value A string holding the value of the field. @param value A string holding the value of the field.
*/ */
void void
replace(boost::string_ref const& name, boost::string_ref value); replace(string_view const& name, string_view value);
/** Replace a field value. /** Replace a field value.
@ -292,8 +292,8 @@ public:
*/ */
template<class T> template<class T>
typename std::enable_if< typename std::enable_if<
! std::is_constructible<boost::string_ref, T>::value>::type ! std::is_constructible<string_view, T>::value>::type
replace(boost::string_ref const& name, T const& value) replace(string_view const& name, T const& value)
{ {
replace(name, replace(name,
boost::lexical_cast<std::string>(value)); boost::lexical_cast<std::string>(value));
@ -303,38 +303,38 @@ public:
private: private:
#endif #endif
boost::string_ref string_view
method() const method() const
{ {
return (*this)[":method"]; return (*this)[":method"];
} }
void void
method(boost::string_ref const& s) method(string_view const& s)
{ {
return this->replace(":method", s); return this->replace(":method", s);
} }
boost::string_ref string_view
target() const target() const
{ {
return (*this)[":target"]; return (*this)[":target"];
} }
void void
target(boost::string_ref const& s) target(string_view const& s)
{ {
return this->replace(":target", s); return this->replace(":target", s);
} }
boost::string_ref string_view
reason() const reason() const
{ {
return (*this)[":reason"]; return (*this)[":reason"];
} }
void void
reason(boost::string_ref const& s) reason(string_view const& s)
{ {
return this->replace(":reason", s); return this->replace(":reason", s);
} }

View File

@ -108,8 +108,8 @@ private:
void void
on_request( on_request(
boost::string_ref const& method, string_view const& method,
boost::string_ref const& path, string_view const& path,
int version, error_code&) int version, error_code&)
{ {
h_.target(path); h_.target(path);
@ -119,7 +119,7 @@ private:
void void
on_response(int status, on_response(int status,
boost::string_ref const& reason, string_view const& reason,
int version, error_code&) int version, error_code&)
{ {
h_.status = status; h_.status = status;
@ -128,8 +128,8 @@ private:
} }
void void
on_field(boost::string_ref const& name, on_field(string_view const& name,
boost::string_ref const& value, string_view const& value,
error_code&) error_code&)
{ {
h_.fields.insert(name, value); h_.fields.insert(name, value);
@ -152,7 +152,7 @@ private:
} }
void void
on_data(boost::string_ref const& s, on_data(string_view const& s,
error_code& ec) error_code& ec)
{ {
} }
@ -168,7 +168,7 @@ private:
void void
on_chunk(std::uint64_t n, on_chunk(std::uint64_t n,
boost::string_ref const& ext, string_view const& ext,
error_code& ec) error_code& ec)
{ {
} }

View File

@ -261,7 +261,7 @@ consume_body(error_code& ec)
template<bool isRequest, bool isDirect, class Derived> template<bool isRequest, bool isDirect, class Derived>
template<class ConstBufferSequence> template<class ConstBufferSequence>
inline inline
boost::string_ref string_view
basic_parser<isRequest, isDirect, Derived>:: basic_parser<isRequest, isDirect, Derived>::
maybe_flatten( maybe_flatten(
ConstBufferSequence const& buffers) ConstBufferSequence const& buffers)
@ -552,7 +552,7 @@ parse_fields(char const*& it,
it = term; it = term;
} }
} }
boost::string_ref value{ string_view value{
s.data(), s.size()}; s.data(), s.size()};
do_field(name, value, ec); do_field(name, value, ec);
if(ec) if(ec)
@ -568,8 +568,8 @@ template<bool isRequest, bool isDirect, class Derived>
void void
basic_parser<isRequest, isDirect, Derived>:: basic_parser<isRequest, isDirect, Derived>::
do_field( do_field(
boost::string_ref const& name, string_view const& name,
boost::string_ref const& value, string_view const& value,
error_code& ec) error_code& ec)
{ {
// Connection // Connection
@ -996,7 +996,7 @@ parse_body(char const* p,
std::size_t n, error_code& ec) std::size_t n, error_code& ec)
{ {
n = beast::detail::clamp(len_, n); n = beast::detail::clamp(len_, n);
body_ = boost::string_ref{p, n}; body_ = string_view{p, n};
impl().on_data(body_, ec); impl().on_data(body_, ec);
if(ec) if(ec)
return 0; return 0;
@ -1017,7 +1017,7 @@ basic_parser<isRequest, isDirect, Derived>::
parse_body_to_eof(char const* p, parse_body_to_eof(char const* p,
std::size_t n, error_code& ec) std::size_t n, error_code& ec)
{ {
body_ = boost::string_ref{p, n}; body_ = string_view{p, n};
impl().on_data(body_, ec); impl().on_data(body_, ec);
if(ec) if(ec)
return 0; return 0;
@ -1032,7 +1032,7 @@ parse_chunk_body(char const* p,
std::size_t n, error_code& ec) std::size_t n, error_code& ec)
{ {
n = beast::detail::clamp(len_, n); n = beast::detail::clamp(len_, n);
body_ = boost::string_ref{p, n}; body_ = string_view{p, n};
impl().on_data(body_, ec); impl().on_data(body_, ec);
if(ec) if(ec)
return 0; return 0;

View File

@ -170,7 +170,7 @@ basic_fields(FwdIt first, FwdIt last)
template<class Allocator> template<class Allocator>
std::size_t std::size_t
basic_fields<Allocator>:: basic_fields<Allocator>::
count(boost::string_ref const& name) const count(string_view const& name) const
{ {
auto const it = set_.find(name, less{}); auto const it = set_.find(name, less{});
if(it == set_.end()) if(it == set_.end())
@ -182,7 +182,7 @@ count(boost::string_ref const& name) const
template<class Allocator> template<class Allocator>
auto auto
basic_fields<Allocator>:: basic_fields<Allocator>::
find(boost::string_ref const& name) const -> find(string_view const& name) const ->
iterator iterator
{ {
auto const it = set_.find(name, less{}); auto const it = set_.find(name, less{});
@ -192,9 +192,9 @@ find(boost::string_ref const& name) const ->
} }
template<class Allocator> template<class Allocator>
boost::string_ref const string_view const
basic_fields<Allocator>:: basic_fields<Allocator>::
operator[](boost::string_ref const& name) const operator[](string_view const& name) const
{ {
auto const it = find(name); auto const it = find(name);
if(it == end()) if(it == end())
@ -215,7 +215,7 @@ clear() noexcept
template<class Allocator> template<class Allocator>
std::size_t std::size_t
basic_fields<Allocator>:: basic_fields<Allocator>::
erase(boost::string_ref const& name) erase(string_view const& name)
{ {
auto it = set_.find(name, less{}); auto it = set_.find(name, less{});
if(it == set_.end()) if(it == set_.end())
@ -239,8 +239,8 @@ erase(boost::string_ref const& name)
template<class Allocator> template<class Allocator>
void void
basic_fields<Allocator>:: basic_fields<Allocator>::
insert(boost::string_ref const& name, insert(string_view const& name,
boost::string_ref value) string_view value)
{ {
value = detail::trim(value); value = detail::trim(value);
auto const p = alloc_traits::allocate(this->member(), 1); auto const p = alloc_traits::allocate(this->member(), 1);
@ -252,8 +252,8 @@ insert(boost::string_ref const& name,
template<class Allocator> template<class Allocator>
void void
basic_fields<Allocator>:: basic_fields<Allocator>::
replace(boost::string_ref const& name, replace(string_view const& name,
boost::string_ref value) string_view value)
{ {
value = detail::trim(value); value = detail::trim(value);
erase(name); erase(name);

View File

@ -17,7 +17,7 @@ namespace http {
class param_list::const_iterator class param_list::const_iterator
{ {
using iter_type = boost::string_ref::const_iterator; using iter_type = string_view::const_iterator;
std::string s_; std::string s_;
detail::param_iter pi_; detail::param_iter pi_;
@ -87,7 +87,7 @@ private:
template<class = void> template<class = void>
static static
std::string std::string
unquote(boost::string_ref const& sr); unquote(string_view const& sr);
template<class = void> template<class = void>
void void
@ -133,7 +133,7 @@ cend() const ->
template<class> template<class>
std::string std::string
param_list::const_iterator:: param_list::const_iterator::
unquote(boost::string_ref const& sr) unquote(string_view const& sr)
{ {
std::string s; std::string s;
s.reserve(sr.size()); s.reserve(sr.size());
@ -165,7 +165,7 @@ increment()
pi_.v.second.front() == '"') pi_.v.second.front() == '"')
{ {
s_ = unquote(pi_.v.second); s_ = unquote(pi_.v.second);
pi_.v.second = boost::string_ref{ pi_.v.second = string_view{
s_.data(), s_.size()}; s_.data(), s_.size()};
} }
} }
@ -346,7 +346,7 @@ increment()
if(! detail::is_tchar(*it_)) if(! detail::is_tchar(*it_))
break; break;
} }
v_.first = boost::string_ref{&*p0, v_.first = string_view{&*p0,
static_cast<std::size_t>(it_ - p0)}; static_cast<std::size_t>(it_ - p0)};
detail::param_iter pi; detail::param_iter pi;
pi.it = it_; pi.it = it_;
@ -358,7 +358,7 @@ increment()
if(pi.empty()) if(pi.empty())
break; break;
} }
v_.second = param_list{boost::string_ref{&*it_, v_.second = param_list{string_view{&*it_,
static_cast<std::size_t>(pi.it - it_)}}; static_cast<std::size_t>(pi.it - it_)}};
it_ = pi.it; it_ = pi.it;
return; return;
@ -518,7 +518,7 @@ increment()
if(! detail::is_tchar(*it_)) if(! detail::is_tchar(*it_))
break; break;
} }
v_ = boost::string_ref{&*p0, v_ = string_view{&*p0,
static_cast<std::size_t>(it_ - p0)}; static_cast<std::size_t>(it_ - p0)};
return; return;
} }

View File

@ -10,8 +10,8 @@
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/http/fields.hpp> #include <beast/http/fields.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/integer_sequence.hpp> #include <beast/core/detail/integer_sequence.hpp>
#include <boost/utility/string_ref.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include <tuple> #include <tuple>

View File

@ -157,8 +157,8 @@ private:
void void
on_request( on_request(
boost::string_ref const& method, string_view const& method,
boost::string_ref const& target, string_view const& target,
int version, error_code&) int version, error_code&)
{ {
m_.target(target); m_.target(target);
@ -168,7 +168,7 @@ private:
void void
on_response(int status, on_response(int status,
boost::string_ref const& reason, string_view const& reason,
int version, error_code&) int version, error_code&)
{ {
m_.status = status; m_.status = status;
@ -177,8 +177,8 @@ private:
} }
void void
on_field(boost::string_ref const& name, on_field(string_view const& name,
boost::string_ref const& value, string_view const& value,
error_code&) error_code&)
{ {
m_.fields.insert(name, value); m_.fields.insert(name, value);
@ -223,7 +223,7 @@ private:
} }
void void
on_data(boost::string_ref const& s, on_data(string_view const& s,
error_code& ec) error_code& ec)
{ {
static_assert(! Body::reader::is_direct, ""); static_assert(! Body::reader::is_direct, "");
@ -244,7 +244,7 @@ private:
void void
on_chunk(std::uint64_t, on_chunk(std::uint64_t,
boost::string_ref const&, string_view const&,
error_code&) error_code&)
{ {
} }

View File

@ -49,7 +49,7 @@ namespace http {
*/ */
class param_list class param_list
{ {
boost::string_ref s_; string_view s_;
public: public:
/** The type of each element in the list. /** The type of each element in the list.
@ -59,7 +59,7 @@ public:
be empty). be empty).
*/ */
using value_type = using value_type =
std::pair<boost::string_ref, boost::string_ref>; std::pair<string_view, string_view>;
/// A constant iterator to the list /// A constant iterator to the list
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
@ -77,7 +77,7 @@ public:
must remain valid for the lifetime of the container. must remain valid for the lifetime of the container.
*/ */
explicit explicit
param_list(boost::string_ref const& s) param_list(string_view const& s)
: s_(s) : s_(s)
{ {
} }
@ -137,9 +137,9 @@ public:
*/ */
class ext_list class ext_list
{ {
using iter_type = boost::string_ref::const_iterator; using iter_type = string_view::const_iterator;
boost::string_ref s_; string_view s_;
public: public:
/** The type of each element in the list. /** The type of each element in the list.
@ -148,7 +148,7 @@ public:
second element of the pair is an iterable container holding the second element of the pair is an iterable container holding the
extension's name/value parameters. extension's name/value parameters.
*/ */
using value_type = std::pair<boost::string_ref, param_list>; using value_type = std::pair<string_view, param_list>;
/// A constant iterator to the list /// A constant iterator to the list
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
@ -163,7 +163,7 @@ public:
must remain valid for the lifetime of the container. must remain valid for the lifetime of the container.
*/ */
explicit explicit
ext_list(boost::string_ref const& s) ext_list(string_view const& s)
: s_(s) : s_(s)
{ {
} }
@ -230,13 +230,13 @@ public:
*/ */
class token_list class token_list
{ {
using iter_type = boost::string_ref::const_iterator; using iter_type = string_view::const_iterator;
boost::string_ref s_; string_view s_;
public: public:
/// The type of each element in the token list. /// The type of each element in the token list.
using value_type = boost::string_ref; using value_type = string_view;
/// A constant iterator to the list /// A constant iterator to the list
#if BEAST_DOXYGEN #if BEAST_DOXYGEN
@ -251,7 +251,7 @@ public:
must remain valid for the lifetime of the container. must remain valid for the lifetime of the container.
*/ */
explicit explicit
token_list(boost::string_ref const& s) token_list(string_view const& s)
: s_(s) : s_(s)
{ {
} }

View File

@ -9,10 +9,10 @@
#define BEAST_WEBSOCKET_DETAIL_HYBI13_HPP #define BEAST_WEBSOCKET_DETAIL_HYBI13_HPP
#include <beast/core/static_string.hpp> #include <beast/core/static_string.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/base64.hpp> #include <beast/core/detail/base64.hpp>
#include <beast/core/detail/sha1.hpp> #include <beast/core/detail/sha1.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/utility/string_ref.hpp>
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
@ -49,7 +49,7 @@ make_sec_ws_key(sec_ws_key_type& key, Gen& g)
template<class = void> template<class = void>
void void
make_sec_ws_accept(sec_ws_accept_type& accept, make_sec_ws_accept(sec_ws_accept_type& accept,
boost::string_ref key) string_view key)
{ {
BOOST_ASSERT(key.size() <= sec_ws_key_type::max_size_n); BOOST_ASSERT(key.size() <= sec_ws_key_type::max_size_n);
static_string<sec_ws_key_type::max_size_n + 36> m(key); static_string<sec_ws_key_type::max_size_n + 36> m(key);

View File

@ -46,7 +46,7 @@ struct pmd_offer
template<class = void> template<class = void>
int int
parse_bits(boost::string_ref const& s) parse_bits(string_view const& s)
{ {
if(s.size() == 0) if(s.size() == 0)
return -1; return -1;

View File

@ -42,8 +42,8 @@ class stream<NextLayer>::handshake_op
template<class Decorator> template<class Decorator>
data(Handler& handler, stream<NextLayer>& ws_, data(Handler& handler, stream<NextLayer>& ws_,
response_type* res_p_, response_type* res_p_,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
Decorator const& decorator) Decorator const& decorator)
: cont(beast_asio_helpers:: : cont(beast_asio_helpers::
is_continuation(handler)) is_continuation(handler))
@ -163,8 +163,8 @@ template<class HandshakeHandler>
typename async_completion<HandshakeHandler, typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
stream<NextLayer>:: stream<NextLayer>::
async_handshake(boost::string_ref const& host, async_handshake(string_view const& host,
boost::string_ref const& target, string_view const& target,
HandshakeHandler&& handler) HandshakeHandler&& handler)
{ {
static_assert(is_AsyncStream<next_layer_type>::value, static_assert(is_AsyncStream<next_layer_type>::value,
@ -183,8 +183,8 @@ typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
stream<NextLayer>:: stream<NextLayer>::
async_handshake(response_type& res, async_handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
HandshakeHandler&& handler) HandshakeHandler&& handler)
{ {
static_assert(is_AsyncStream<next_layer_type>::value, static_assert(is_AsyncStream<next_layer_type>::value,
@ -202,8 +202,8 @@ template<class RequestDecorator, class HandshakeHandler>
typename async_completion<HandshakeHandler, typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
stream<NextLayer>:: stream<NextLayer>::
async_handshake_ex(boost::string_ref const& host, async_handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
HandshakeHandler&& handler) HandshakeHandler&& handler)
{ {
@ -226,8 +226,8 @@ typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
stream<NextLayer>:: stream<NextLayer>::
async_handshake_ex(response_type& res, async_handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
HandshakeHandler&& handler) HandshakeHandler&& handler)
{ {
@ -247,8 +247,8 @@ async_handshake_ex(response_type& res,
template<class NextLayer> template<class NextLayer>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake(boost::string_ref const& host, handshake(string_view const& host,
boost::string_ref const& target) string_view const& target)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
"SyncStream requirements not met"); "SyncStream requirements not met");
@ -263,8 +263,8 @@ template<class NextLayer>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake(response_type& res, handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target) string_view const& target)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
"SyncStream requirements not met"); "SyncStream requirements not met");
@ -278,8 +278,8 @@ template<class NextLayer>
template<class RequestDecorator> template<class RequestDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake_ex(boost::string_ref const& host, handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator) RequestDecorator const& decorator)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
@ -298,8 +298,8 @@ template<class RequestDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake_ex(response_type& res, handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator) RequestDecorator const& decorator)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
@ -316,8 +316,8 @@ handshake_ex(response_type& res,
template<class NextLayer> template<class NextLayer>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake(boost::string_ref const& host, handshake(string_view const& host,
boost::string_ref const& target, error_code& ec) string_view const& target, error_code& ec)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
"SyncStream requirements not met"); "SyncStream requirements not met");
@ -329,8 +329,8 @@ template<class NextLayer>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake(response_type& res, handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
error_code& ec) error_code& ec)
{ {
static_assert(is_SyncStream<next_layer_type>::value, static_assert(is_SyncStream<next_layer_type>::value,
@ -343,8 +343,8 @@ template<class NextLayer>
template<class RequestDecorator> template<class RequestDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake_ex(boost::string_ref const& host, handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec) error_code& ec)
{ {
@ -362,8 +362,8 @@ template<class RequestDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
handshake_ex(response_type& res, handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec) error_code& ec)
{ {

View File

@ -127,8 +127,8 @@ template<class RequestDecorator>
void void
stream<NextLayer>:: stream<NextLayer>::
do_handshake(response_type* res_p, do_handshake(response_type* res_p,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec) error_code& ec)
{ {
@ -156,8 +156,8 @@ template<class Decorator>
request_type request_type
stream<NextLayer>:: stream<NextLayer>::
build_request(detail::sec_ws_key_type& key, build_request(detail::sec_ws_key_type& key,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
Decorator const& decorator) Decorator const& decorator)
{ {
request_type req; request_type req;

View File

@ -16,9 +16,9 @@
#include <beast/http/string_body.hpp> #include <beast/http/string_body.hpp>
#include <beast/core/async_completion.hpp> #include <beast/core/async_completion.hpp>
#include <beast/core/buffered_read_stream.hpp> #include <beast/core/buffered_read_stream.hpp>
#include <beast/core/string_view.hpp>
#include <beast/core/detail/get_lowest_layer.hpp> #include <beast/core/detail/get_lowest_layer.hpp>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/utility/string_ref.hpp>
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
@ -1465,8 +1465,8 @@ public:
@endcode @endcode
*/ */
void void
handshake(boost::string_ref const& host, handshake(string_view const& host,
boost::string_ref const& target); string_view const& target);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1514,8 +1514,8 @@ public:
*/ */
void void
handshake(response_type& res, handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target); string_view const& target);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1572,8 +1572,8 @@ public:
*/ */
template<class RequestDecorator> template<class RequestDecorator>
void void
handshake_ex(boost::string_ref const& host, handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator); RequestDecorator const& decorator);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1636,8 +1636,8 @@ public:
template<class RequestDecorator> template<class RequestDecorator>
void void
handshake_ex(response_type& res, handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator); RequestDecorator const& decorator);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1679,8 +1679,8 @@ public:
@endcode @endcode
*/ */
void void
handshake(boost::string_ref const& host, handshake(string_view const& host,
boost::string_ref const& target, error_code& ec); string_view const& target, error_code& ec);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1726,8 +1726,8 @@ public:
*/ */
void void
handshake(response_type& res, handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
error_code& ec); error_code& ec);
/** Send an HTTP WebSocket Upgrade request and receive the response. /** Send an HTTP WebSocket Upgrade request and receive the response.
@ -1784,8 +1784,8 @@ public:
*/ */
template<class RequestDecorator> template<class RequestDecorator>
void void
handshake_ex(boost::string_ref const& host, handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec); error_code& ec);
@ -1848,8 +1848,8 @@ public:
template<class RequestDecorator> template<class RequestDecorator>
void void
handshake_ex(response_type& res, handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec); error_code& ec);
@ -1901,8 +1901,8 @@ public:
typename async_completion<HandshakeHandler, typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
#endif #endif
async_handshake(boost::string_ref const& host, async_handshake(string_view const& host,
boost::string_ref const& target, string_view const& target,
HandshakeHandler&& handler); HandshakeHandler&& handler);
/** Start an asynchronous operation to send an upgrade request and receive the response. /** Start an asynchronous operation to send an upgrade request and receive the response.
@ -1958,8 +1958,8 @@ public:
void(error_code)>::result_type void(error_code)>::result_type
#endif #endif
async_handshake(response_type& res, async_handshake(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
HandshakeHandler&& handler); HandshakeHandler&& handler);
/** Start an asynchronous operation to send an upgrade request and receive the response. /** Start an asynchronous operation to send an upgrade request and receive the response.
@ -2019,8 +2019,8 @@ public:
typename async_completion<HandshakeHandler, typename async_completion<HandshakeHandler,
void(error_code)>::result_type void(error_code)>::result_type
#endif #endif
async_handshake_ex(boost::string_ref const& host, async_handshake_ex(string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
HandshakeHandler&& handler); HandshakeHandler&& handler);
@ -2086,8 +2086,8 @@ public:
void(error_code)>::result_type void(error_code)>::result_type
#endif #endif
async_handshake_ex(response_type& res, async_handshake_ex(response_type& res,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
HandshakeHandler&& handler); HandshakeHandler&& handler);
@ -2968,16 +2968,16 @@ private:
template<class RequestDecorator> template<class RequestDecorator>
void void
do_handshake(response_type* res_p, do_handshake(response_type* res_p,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
RequestDecorator const& decorator, RequestDecorator const& decorator,
error_code& ec); error_code& ec);
template<class Decorator> template<class Decorator>
request_type request_type
build_request(detail::sec_ws_key_type& key, build_request(detail::sec_ws_key_type& key,
boost::string_ref const& host, string_view const& host,
boost::string_ref const& target, string_view const& target,
Decorator const& decorator); Decorator const& decorator);
template<class Decorator> template<class Decorator>

View File

@ -37,6 +37,7 @@ unit-test core-tests :
core/static_buffer.cpp core/static_buffer.cpp
core/static_string.cpp core/static_string.cpp
core/stream_concepts.cpp core/stream_concepts.cpp
core/string_view.cpp
core/base64.cpp core/base64.cpp
core/empty_base_optimization.cpp core/empty_base_optimization.cpp
core/get_lowest_layer.cpp core/get_lowest_layer.cpp

View File

@ -30,6 +30,7 @@ add_executable (core-tests
static_buffer.cpp static_buffer.cpp
static_string.cpp static_string.cpp
stream_concepts.cpp stream_concepts.cpp
string_view.cpp
base64.cpp base64.cpp
empty_base_optimization.cpp empty_base_optimization.cpp
get_lowest_layer.cpp get_lowest_layer.cpp

View File

@ -123,13 +123,13 @@ public:
} }
{ {
static_string<3> s1( static_string<3> s1(
boost::string_ref("123")); string_view("123"));
BEAST_EXPECT(s1 == "123"); BEAST_EXPECT(s1 == "123");
BEAST_EXPECT(*s1.end() == 0); BEAST_EXPECT(*s1.end() == 0);
try try
{ {
static_string<2> s2( static_string<2> s2(
boost::string_ref("123")); string_view("123"));
fail("", __FILE__, __LINE__); fail("", __FILE__, __LINE__);
} }
catch(std::length_error const&) catch(std::length_error const&)
@ -232,13 +232,13 @@ public:
} }
{ {
static_string<3> s1; static_string<3> s1;
s1 = boost::string_ref("123"); s1 = string_view("123");
BEAST_EXPECT(s1 == "123"); BEAST_EXPECT(s1 == "123");
BEAST_EXPECT(*s1.end() == 0); BEAST_EXPECT(*s1.end() == 0);
try try
{ {
static_string<1> s2; static_string<1> s2;
s2 = boost::string_ref("123"); s2 = string_view("123");
fail("", __FILE__, __LINE__); fail("", __FILE__, __LINE__);
} }
catch(std::length_error const&) catch(std::length_error const&)
@ -370,15 +370,15 @@ public:
} }
{ {
static_string<5> s1; static_string<5> s1;
s1.assign(boost::string_ref("123")); s1.assign(string_view("123"));
BEAST_EXPECT(s1 == "123"); BEAST_EXPECT(s1 == "123");
BEAST_EXPECT(*s1.end() == 0); BEAST_EXPECT(*s1.end() == 0);
s1.assign(boost::string_ref("12345")); s1.assign(string_view("12345"));
BEAST_EXPECT(s1 == "12345"); BEAST_EXPECT(s1 == "12345");
BEAST_EXPECT(*s1.end() == 0); BEAST_EXPECT(*s1.end() == 0);
try try
{ {
s1.assign(boost::string_ref("1234567")); s1.assign(string_view("1234567"));
fail("", __FILE__, __LINE__); fail("", __FILE__, __LINE__);
} }
catch(std::length_error const&) catch(std::length_error const&)
@ -483,7 +483,7 @@ public:
} }
{ {
static_string<3> s("123"); static_string<3> s("123");
boost::string_ref sv = s; string_view sv = s;
BEAST_EXPECT(static_string<5>(sv) == "123"); BEAST_EXPECT(static_string<5>(sv) == "123");
} }
} }
@ -750,13 +750,13 @@ public:
} }
{ {
static_string<5> s1("123"); static_string<5> s1("123");
s1.insert(1, boost::string_ref("UV")); s1.insert(1, string_view("UV"));
BEAST_EXPECT(s1 == "1UV23"); BEAST_EXPECT(s1 == "1UV23");
BEAST_EXPECT(*s1.end() == 0); BEAST_EXPECT(*s1.end() == 0);
try try
{ {
static_string<4> s2("123"); static_string<4> s2("123");
s2.insert(1, boost::string_ref("UV")); s2.insert(1, string_view("UV"));
fail("", __FILE__, __LINE__); fail("", __FILE__, __LINE__);
} }
catch(std::length_error const&) catch(std::length_error const&)
@ -766,7 +766,7 @@ public:
try try
{ {
static_string<5> s2("123"); static_string<5> s2("123");
s2.insert(5, boost::string_ref("UV")); s2.insert(5, string_view("UV"));
fail("", __FILE__, __LINE__); fail("", __FILE__, __LINE__);
} }
catch(std::out_of_range const&) catch(std::out_of_range const&)
@ -1024,7 +1024,7 @@ public:
} }
} }
{ {
boost::string_ref s1("XYZ"); string_view s1("XYZ");
static_string<5> s2("12"); static_string<5> s2("12");
s2.append(s1); s2.append(s1);
BEAST_EXPECT(s2 == "12XYZ"); BEAST_EXPECT(s2 == "12XYZ");
@ -1124,7 +1124,7 @@ public:
} }
} }
{ {
boost::string_ref s1("34"); string_view s1("34");
static_string<4> s2("12"); static_string<4> s2("12");
s2 += s1; s2 += s1;
BEAST_EXPECT(s2 == "1234"); BEAST_EXPECT(s2 == "1234");

View File

@ -0,0 +1,9 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/core/string_view.hpp>

View File

@ -218,7 +218,7 @@ public:
template<bool isRequest, class Pred> template<bool isRequest, class Pred>
void void
good(boost::string_ref const& s, good(string_view const& s,
Pred const& pred, bool skipBody = false) Pred const& pred, bool skipBody = false)
{ {
using boost::asio::buffer; using boost::asio::buffer;
@ -240,7 +240,7 @@ public:
template<bool isRequest> template<bool isRequest>
void void
good(boost::string_ref const& s) good(string_view const& s)
{ {
good<isRequest>(s, good<isRequest>(s,
[](test_parser<isRequest> const&) [](test_parser<isRequest> const&)
@ -250,7 +250,7 @@ public:
template<bool isRequest> template<bool isRequest>
void void
bad(boost::string_ref const& s, bad(string_view const& s,
error_code const& ev, bool skipBody = false) error_code const& ev, bool skipBody = false)
{ {
using boost::asio::buffer; using boost::asio::buffer;

View File

@ -176,7 +176,7 @@ public:
} }
void void
write(boost::string_ref const& s, write(string_view const& s,
error_code& ec) error_code& ec)
{ {
body_.append(s.data(), s.size()); body_.append(s.data(), s.size());
@ -464,7 +464,7 @@ public:
struct bodyHandler struct bodyHandler
{ {
void void
operator()(boost::string_ref const& body) const operator()(string_view const& body) const
{ {
// called for each piece of the body, // called for each piece of the body,
} }

View File

@ -19,7 +19,7 @@ namespace http {
template<class = void> template<class = void>
std::string std::string
escaped_string(boost::string_ref const& s) escaped_string(string_view const& s)
{ {
std::string out; std::string out;
out.reserve(s.size()); out.reserve(s.size());

View File

@ -168,22 +168,22 @@ public:
boost::asio::mutable_buffers_1; boost::asio::mutable_buffers_1;
void void
on_request(boost::string_ref const&, on_request(string_view const&,
boost::string_ref const&, string_view const&,
int, error_code&) int, error_code&)
{ {
} }
void void
on_response(int, on_response(int,
boost::string_ref const&, string_view const&,
int, error_code&) int, error_code&)
{ {
} }
void void
on_field(boost::string_ref const&, on_field(string_view const&,
boost::string_ref const&, string_view const&,
error_code&) error_code&)
{ {
} }
@ -205,20 +205,20 @@ public:
} }
void void
on_data(boost::string_ref const&, on_data(string_view const&,
error_code& ec) error_code& ec)
{ {
} }
void void
on_chunk(std::uint64_t, on_chunk(std::uint64_t,
boost::string_ref const&, string_view const&,
error_code&) error_code&)
{ {
} }
void void
on_body(boost::string_ref const&, on_body(string_view const&,
error_code&) error_code&)
{ {
} }

View File

@ -30,7 +30,7 @@ public:
static static
std::string std::string
str(boost::string_ref const& s) str(string_view const& s)
{ {
return std::string(s.data(), s.size()); return std::string(s.data(), s.size());
} }
@ -241,7 +241,7 @@ public:
template<class Policy> template<class Policy>
static static
std::vector<std::string> std::vector<std::string>
to_vector(boost::string_ref const& in) to_vector(string_view const& in)
{ {
std::vector<std::string> v; std::vector<std::string> v;
detail::basic_parsed_list<Policy> list{in}; detail::basic_parsed_list<Policy> list{in};
@ -253,7 +253,7 @@ public:
template<class Policy> template<class Policy>
void void
validate(boost::string_ref const& in, validate(string_view const& in,
std::vector<std::string> const& v) std::vector<std::string> const& v)
{ {
BEAST_EXPECT(to_vector<Policy>(in) == v); BEAST_EXPECT(to_vector<Policy>(in) == v);
@ -261,7 +261,7 @@ public:
template<class Policy> template<class Policy>
void void
good(boost::string_ref const& in) good(string_view const& in)
{ {
BEAST_EXPECT(validate_list( BEAST_EXPECT(validate_list(
detail::basic_parsed_list<Policy>{in})); detail::basic_parsed_list<Policy>{in}));
@ -269,7 +269,7 @@ public:
template<class Policy> template<class Policy>
void void
good(boost::string_ref const& in, good(string_view const& in,
std::vector<std::string> const& v) std::vector<std::string> const& v)
{ {
BEAST_EXPECT(validate_list( BEAST_EXPECT(validate_list(
@ -279,7 +279,7 @@ public:
template<class Policy> template<class Policy>
void void
bad(boost::string_ref const& in) bad(string_view const& in)
{ {
BEAST_EXPECT(! validate_list( BEAST_EXPECT(! validate_list(
detail::basic_parsed_list<Policy>{in})); detail::basic_parsed_list<Policy>{in}));

View File

@ -51,8 +51,8 @@ public:
void void
on_request( on_request(
boost::string_ref const& method_, string_view const& method_,
boost::string_ref const& path_, string_view const& path_,
int version_, error_code& ec) int version_, error_code& ec)
{ {
method = std::string( method = std::string(
@ -67,7 +67,7 @@ public:
void void
on_response(int status_, on_response(int status_,
boost::string_ref const& reason_, string_view const& reason_,
int version_, error_code& ec) int version_, error_code& ec)
{ {
status = status_; status = status_;
@ -80,8 +80,8 @@ public:
} }
void void
on_field(boost::string_ref const&, on_field(string_view const&,
boost::string_ref const&, string_view const&,
error_code& ec) error_code& ec)
{ {
got_on_field = true; got_on_field = true;
@ -116,7 +116,7 @@ public:
} }
void void
on_data(boost::string_ref const& s, on_data(string_view const& s,
error_code& ec) error_code& ec)
{ {
body.append(s.data(), s.size()); body.append(s.data(), s.size());
@ -124,7 +124,7 @@ public:
void void
on_chunk(std::uint64_t, on_chunk(std::uint64_t,
boost::string_ref const&, string_view const&,
error_code& ec) error_code& ec)
{ {
got_on_chunk = true; got_on_chunk = true;

View File

@ -198,8 +198,8 @@ public:
template<class NextLayer> template<class NextLayer>
void void
handshake(stream<NextLayer>& ws, handshake(stream<NextLayer>& ws,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path) const string_view const& path) const
{ {
ws.handshake(uri, path); ws.handshake(uri, path);
} }
@ -208,8 +208,8 @@ public:
void void
handshake(stream<NextLayer>& ws, handshake(stream<NextLayer>& ws,
response_type& res, response_type& res,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path) const string_view const& path) const
{ {
ws.handshake(res, uri, path); ws.handshake(res, uri, path);
} }
@ -217,8 +217,8 @@ public:
template<class NextLayer, class Decorator> template<class NextLayer, class Decorator>
void void
handshake_ex(stream<NextLayer>& ws, handshake_ex(stream<NextLayer>& ws,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path, string_view const& path,
Decorator const& d) const Decorator const& d) const
{ {
ws.handshake_ex(uri, path, d); ws.handshake_ex(uri, path, d);
@ -228,8 +228,8 @@ public:
void void
handshake_ex(stream<NextLayer>& ws, handshake_ex(stream<NextLayer>& ws,
response_type& res, response_type& res,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path, string_view const& path,
Decorator const& d) const Decorator const& d) const
{ {
ws.handshake_ex(res, uri, path, d); ws.handshake_ex(res, uri, path, d);
@ -409,8 +409,8 @@ public:
template<class NextLayer> template<class NextLayer>
void void
handshake(stream<NextLayer>& ws, handshake(stream<NextLayer>& ws,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path) const string_view const& path) const
{ {
error_code ec; error_code ec;
ws.async_handshake( ws.async_handshake(
@ -423,8 +423,8 @@ public:
void void
handshake(stream<NextLayer>& ws, handshake(stream<NextLayer>& ws,
response_type& res, response_type& res,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path) const string_view const& path) const
{ {
error_code ec; error_code ec;
ws.async_handshake( ws.async_handshake(
@ -436,8 +436,8 @@ public:
template<class NextLayer, class Decorator> template<class NextLayer, class Decorator>
void void
handshake_ex(stream<NextLayer>& ws, handshake_ex(stream<NextLayer>& ws,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path, string_view const& path,
Decorator const &d) const Decorator const &d) const
{ {
error_code ec; error_code ec;
@ -451,8 +451,8 @@ public:
void void
handshake_ex(stream<NextLayer>& ws, handshake_ex(stream<NextLayer>& ws,
response_type& res, response_type& res,
boost::string_ref const& uri, string_view const& uri,
boost::string_ref const& path, string_view const& path,
Decorator const &d) const Decorator const &d) const
{ {
error_code ec; error_code ec;