From 806979e37bd20b169299e3b4315bc4b871ad3faa Mon Sep 17 00:00:00 2001 From: Domen Vrankar Date: Wed, 5 Sep 2018 21:17:53 +0200 Subject: [PATCH] Add BOOST_BEAST_USE_STD_STRING_VIEW: fix #1133, fix #1241 When the macro BOOST_BEAST_USE_STD_STRING_VIEW is defined, Beast will use std::string_view instead of boost::string_view. The name boost::beast::string_view is a type alias for the chosen view type. --- CHANGELOG.md | 1 + doc/qbk/09_releases.qbk | 5 ++++ include/boost/beast/core/string.hpp | 28 +++++++++++++++---- .../beast/http/detail/basic_parsed_list.hpp | 2 +- include/boost/beast/http/detail/rfc7230.hpp | 10 +++---- include/boost/beast/http/impl/field.ipp | 2 +- include/boost/beast/http/impl/verb.ipp | 2 +- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 361bc2c3..38b0f39a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 184: * Remove extraneous function * Fix some typos +* Add BOOST_BEAST_USE_STD_STRING_VIEW -------------------------------------------------------------------------------- diff --git a/doc/qbk/09_releases.qbk b/doc/qbk/09_releases.qbk index 91f30d58..96acbba4 100644 --- a/doc/qbk/09_releases.qbk +++ b/doc/qbk/09_releases.qbk @@ -13,6 +13,10 @@ [heading Boost 1.69] +[* New Features] + +* ([issue 1133]) Add `BOOST_BEAST_USE_STD_STRING_VIEW` + [*Fixes] * ([issue 1245]) Fix a rare case of incorrect UTF8 validation @@ -25,6 +29,7 @@ + [heading Boost 1.68] This version fixes a missing executor work guard in all composed operations diff --git a/include/boost/beast/core/string.hpp b/include/boost/beast/core/string.hpp index 27bfa571..de94d2e6 100644 --- a/include/boost/beast/core/string.hpp +++ b/include/boost/beast/core/string.hpp @@ -12,19 +12,35 @@ #include #include + +#if defined(BOOST_BEAST_USE_STD_STRING_VIEW) +#include +#else #include +#endif + #include namespace boost { namespace beast { -/// The type of string view used by the library -using string_view = boost::string_view; +#if defined(BOOST_BEAST_USE_STD_STRING_VIEW) + /// The type of string view used by the library + using string_view = std::string_view; -/// The type of basic string view used by the library -template -using basic_string_view = - boost::basic_string_view; + /// The type of basic string view used by the library + template + using basic_string_view = + std::basic_string_view; +#else + /// The type of string view used by the library + using string_view = boost::string_view; + + /// The type of basic string view used by the library + template + using basic_string_view = + boost::basic_string_view; +#endif namespace detail { diff --git a/include/boost/beast/http/detail/basic_parsed_list.hpp b/include/boost/beast/http/detail/basic_parsed_list.hpp index 011f5a7a..5577fba7 100644 --- a/include/boost/beast/http/detail/basic_parsed_list.hpp +++ b/include/boost/beast/http/detail/basic_parsed_list.hpp @@ -110,7 +110,7 @@ public: basic_parsed_list const& list, bool at_end) : list_(&list) , it_(at_end ? nullptr : - list.s_.begin()) + list.s_.data()) { if(! at_end) increment(); diff --git a/include/boost/beast/http/detail/rfc7230.hpp b/include/boost/beast/http/detail/rfc7230.hpp index fac67905..afe35691 100644 --- a/include/boost/beast/http/detail/rfc7230.hpp +++ b/include/boost/beast/http/detail/rfc7230.hpp @@ -429,11 +429,11 @@ struct opt_token_list_policy char const*& it, string_view s) const { v = {}; - auto need_comma = it != s.begin(); + auto need_comma = it != s.data(); for(;;) { - detail::skip_ows(it, s.end()); - if(it == s.end()) + detail::skip_ows(it, (s.data() + s.size())); + if(it == (s.data() + s.size())) { it = nullptr; return true; @@ -447,12 +447,12 @@ struct opt_token_list_policy for(;;) { ++it; - if(it == s.end()) + if(it == (s.data() + s.size())) break; if(! detail::is_token_char(*it)) break; } - v = string_view{&*p0, + v = string_view{p0, static_cast(it - p0)}; return true; } diff --git a/include/boost/beast/http/impl/field.ipp b/include/boost/beast/http/impl/field.ipp index 467a40ae..b61a0ba8 100644 --- a/include/boost/beast/http/impl/field.ipp +++ b/include/boost/beast/http/impl/field.ipp @@ -51,7 +51,7 @@ struct field_table { auto p1 = lhs.data(); auto p2 = rhs.data(); - auto pend = lhs.end(); + auto pend = p1 + lhs.size(); char a, b; while(p1 < pend) { diff --git a/include/boost/beast/http/impl/verb.ipp b/include/boost/beast/http/impl/verb.ipp index bfd703d0..36a1734c 100644 --- a/include/boost/beast/http/impl/verb.ipp +++ b/include/boost/beast/http/impl/verb.ipp @@ -127,7 +127,7 @@ string_to_verb(string_view v) ++s; ++p; if(! *s) - return p == sv.end(); + return p == (sv.data() + sv.size()); } }; auto c = v[0];