mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 14:24:31 +02:00
Style tidying
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include <boost/beast/core/detail/temporary_buffer.hpp>
|
||||
#include <boost/beast/core/detail/clamp.hpp>
|
||||
#include <boost/core/exchange.hpp>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
@@ -21,44 +21,46 @@ namespace boost {
|
||||
namespace beast {
|
||||
namespace detail {
|
||||
|
||||
|
||||
void
|
||||
temporary_buffer::append(string_view sv)
|
||||
temporary_buffer::
|
||||
append(string_view s)
|
||||
{
|
||||
grow(sv.size());
|
||||
unchecked_append(sv);
|
||||
grow(s.size());
|
||||
unchecked_append(s);
|
||||
}
|
||||
|
||||
void
|
||||
temporary_buffer::append(string_view sv1, string_view sv2)
|
||||
temporary_buffer::
|
||||
append(string_view s1, string_view s2)
|
||||
{
|
||||
grow(sv1.size() + sv2.size());
|
||||
unchecked_append(sv1);
|
||||
unchecked_append(sv2);
|
||||
grow(s1.size() + s2.size());
|
||||
unchecked_append(s1);
|
||||
unchecked_append(s2);
|
||||
}
|
||||
|
||||
void
|
||||
temporary_buffer::unchecked_append(string_view sv)
|
||||
temporary_buffer::
|
||||
unchecked_append(string_view s)
|
||||
{
|
||||
auto n = sv.size();
|
||||
std::memcpy(&data_[size_], sv.data(), n);
|
||||
auto n = s.size();
|
||||
std::memcpy(&data_[size_], s.data(), n);
|
||||
size_ += n;
|
||||
}
|
||||
|
||||
void
|
||||
temporary_buffer::grow(std::size_t sv_size)
|
||||
temporary_buffer::
|
||||
grow(std::size_t n)
|
||||
{
|
||||
if (capacity_ - size_ >= sv_size)
|
||||
{
|
||||
if (capacity_ - size_ >= n)
|
||||
return;
|
||||
}
|
||||
|
||||
auto const new_cap = (sv_size + size_) * 2u;
|
||||
BOOST_ASSERT(!detail::sum_exceeds(sv_size, size_, new_cap));
|
||||
char* const p = new char[new_cap];
|
||||
auto const capacity = (n + size_) * 2u;
|
||||
BOOST_ASSERT(! detail::sum_exceeds(
|
||||
n, size_, capacity));
|
||||
char* const p = new char[capacity];
|
||||
std::memcpy(p, data_, size_);
|
||||
deallocate(boost::exchange(data_, p));
|
||||
capacity_ = new_cap;
|
||||
capacity_ = capacity;
|
||||
}
|
||||
} // detail
|
||||
} // beast
|
||||
|
@@ -10,35 +10,16 @@
|
||||
#ifndef BOOST_BEAST_DETAIL_STRING_HPP
|
||||
#define BOOST_BEAST_DETAIL_STRING_HPP
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#if defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#else
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#endif
|
||||
#include <boost/beast/core/string_type.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
namespace detail {
|
||||
|
||||
#if defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
||||
using string_view = std::string_view;
|
||||
|
||||
template<class CharT, class Traits>
|
||||
using basic_string_view =
|
||||
std::basic_string_view<CharT, Traits>;
|
||||
#else
|
||||
using string_view = boost::string_view;
|
||||
|
||||
template<class CharT, class Traits>
|
||||
using basic_string_view =
|
||||
boost::basic_string_view<CharT, Traits>;
|
||||
#endif
|
||||
|
||||
inline string_view operator "" _sv(char const* p, std::size_t n)
|
||||
inline
|
||||
string_view
|
||||
operator"" _sv(char const* p, std::size_t n)
|
||||
{
|
||||
return string_view{p, n};
|
||||
}
|
||||
|
@@ -22,12 +22,8 @@ namespace detail {
|
||||
struct temporary_buffer
|
||||
{
|
||||
temporary_buffer() = default;
|
||||
|
||||
temporary_buffer(temporary_buffer const&) = delete;
|
||||
temporary_buffer(temporary_buffer&&) = delete;
|
||||
|
||||
temporary_buffer& operator=(temporary_buffer const&) = delete;
|
||||
temporary_buffer& operator=(temporary_buffer&&) = delete;
|
||||
|
||||
~temporary_buffer() noexcept
|
||||
{
|
||||
@@ -36,11 +32,11 @@ struct temporary_buffer
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
append(string_view sv);
|
||||
append(string_view s);
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
append(string_view sv1, string_view sv2);
|
||||
append(string_view s1, string_view s2);
|
||||
|
||||
string_view
|
||||
view() const noexcept
|
||||
@@ -57,11 +53,11 @@ struct temporary_buffer
|
||||
private:
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
unchecked_append(string_view sv);
|
||||
unchecked_append(string_view s);
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
grow(std::size_t sv_size);
|
||||
grow(std::size_t n);
|
||||
|
||||
void
|
||||
deallocate(char* data) noexcept
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#define BOOST_BEAST_IMPL_STRING_IPP
|
||||
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/core/detail/string.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -40,7 +41,8 @@ iequals(
|
||||
slow:
|
||||
do
|
||||
{
|
||||
if(detail::ascii_tolower(a) != detail::ascii_tolower(b))
|
||||
if( detail::ascii_tolower(a) !=
|
||||
detail::ascii_tolower(b))
|
||||
return false;
|
||||
a = *p1++;
|
||||
b = *p2++;
|
||||
@@ -51,8 +53,8 @@ slow:
|
||||
|
||||
bool
|
||||
iless::operator()(
|
||||
string_view lhs,
|
||||
string_view rhs) const
|
||||
string_view lhs,
|
||||
string_view rhs) const
|
||||
{
|
||||
using std::begin;
|
||||
using std::end;
|
||||
|
@@ -10,18 +10,12 @@
|
||||
#ifndef BOOST_BEAST_STRING_HPP
|
||||
#define BOOST_BEAST_STRING_HPP
|
||||
|
||||
#include <boost/beast/core/detail/string.hpp>
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/beast/core/string_type.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
/// The type of string view used by the library
|
||||
using detail::string_view;
|
||||
|
||||
/// The type of basic string view used by the library
|
||||
template<class CharT, class Traits>
|
||||
using basic_string_view = detail::basic_string_view<CharT, Traits>;
|
||||
|
||||
/** Returns `true` if two strings are equal, using a case-insensitive comparison.
|
||||
|
||||
The case-comparison operation is defined only for low-ASCII characters.
|
||||
|
45
include/boost/beast/core/string_type.hpp
Normal file
45
include/boost/beast/core/string_type.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BOOST_BEAST_STRING_TYPE_HPP
|
||||
#define BOOST_BEAST_STRING_TYPE_HPP
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
|
||||
#if defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#else
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
#if BOOST_BEAST_DOXYGEN || ! defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
||||
/// 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<class CharT, class Traits>
|
||||
using basic_string_view =
|
||||
boost::basic_string_view<CharT, Traits>;
|
||||
|
||||
#else
|
||||
using string_view = std::string_view;
|
||||
|
||||
template<class CharT, class Traits>
|
||||
using basic_string_view =
|
||||
std::basic_string_view<CharT, Traits>;
|
||||
|
||||
#endif
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user