mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 14:54:32 +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/temporary_buffer.hpp>
|
||||||
#include <boost/beast/core/detail/clamp.hpp>
|
#include <boost/beast/core/detail/clamp.hpp>
|
||||||
#include <boost/core/exchange.hpp>
|
#include <boost/core/exchange.hpp>
|
||||||
|
#include <boost/assert.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@@ -21,44 +21,46 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
temporary_buffer::append(string_view sv)
|
temporary_buffer::
|
||||||
|
append(string_view s)
|
||||||
{
|
{
|
||||||
grow(sv.size());
|
grow(s.size());
|
||||||
unchecked_append(sv);
|
unchecked_append(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
temporary_buffer::append(string_view sv1, string_view sv2)
|
temporary_buffer::
|
||||||
|
append(string_view s1, string_view s2)
|
||||||
{
|
{
|
||||||
grow(sv1.size() + sv2.size());
|
grow(s1.size() + s2.size());
|
||||||
unchecked_append(sv1);
|
unchecked_append(s1);
|
||||||
unchecked_append(sv2);
|
unchecked_append(s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
temporary_buffer::unchecked_append(string_view sv)
|
temporary_buffer::
|
||||||
|
unchecked_append(string_view s)
|
||||||
{
|
{
|
||||||
auto n = sv.size();
|
auto n = s.size();
|
||||||
std::memcpy(&data_[size_], sv.data(), n);
|
std::memcpy(&data_[size_], s.data(), n);
|
||||||
size_ += n;
|
size_ += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
auto const new_cap = (sv_size + size_) * 2u;
|
auto const capacity = (n + size_) * 2u;
|
||||||
BOOST_ASSERT(!detail::sum_exceeds(sv_size, size_, new_cap));
|
BOOST_ASSERT(! detail::sum_exceeds(
|
||||||
char* const p = new char[new_cap];
|
n, size_, capacity));
|
||||||
|
char* const p = new char[capacity];
|
||||||
std::memcpy(p, data_, size_);
|
std::memcpy(p, data_, size_);
|
||||||
deallocate(boost::exchange(data_, p));
|
deallocate(boost::exchange(data_, p));
|
||||||
capacity_ = new_cap;
|
capacity_ = capacity;
|
||||||
}
|
}
|
||||||
} // detail
|
} // detail
|
||||||
} // beast
|
} // beast
|
||||||
|
@@ -10,35 +10,16 @@
|
|||||||
#ifndef BOOST_BEAST_DETAIL_STRING_HPP
|
#ifndef BOOST_BEAST_DETAIL_STRING_HPP
|
||||||
#define BOOST_BEAST_DETAIL_STRING_HPP
|
#define BOOST_BEAST_DETAIL_STRING_HPP
|
||||||
|
|
||||||
#include <boost/beast/core/detail/config.hpp>
|
#include <boost/beast/core/string_type.hpp>
|
||||||
#include <boost/version.hpp>
|
|
||||||
|
|
||||||
#if defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
|
||||||
#include <string_view>
|
|
||||||
#else
|
|
||||||
#include <boost/utility/string_view.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
#if defined(BOOST_BEAST_USE_STD_STRING_VIEW)
|
inline
|
||||||
using string_view = std::string_view;
|
string_view
|
||||||
|
operator"" _sv(char const* p, std::size_t n)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
return string_view{p, n};
|
return string_view{p, n};
|
||||||
}
|
}
|
||||||
|
@@ -22,12 +22,8 @@ namespace detail {
|
|||||||
struct temporary_buffer
|
struct temporary_buffer
|
||||||
{
|
{
|
||||||
temporary_buffer() = default;
|
temporary_buffer() = default;
|
||||||
|
|
||||||
temporary_buffer(temporary_buffer const&) = delete;
|
temporary_buffer(temporary_buffer const&) = delete;
|
||||||
temporary_buffer(temporary_buffer&&) = delete;
|
|
||||||
|
|
||||||
temporary_buffer& operator=(temporary_buffer const&) = delete;
|
temporary_buffer& operator=(temporary_buffer const&) = delete;
|
||||||
temporary_buffer& operator=(temporary_buffer&&) = delete;
|
|
||||||
|
|
||||||
~temporary_buffer() noexcept
|
~temporary_buffer() noexcept
|
||||||
{
|
{
|
||||||
@@ -36,11 +32,11 @@ struct temporary_buffer
|
|||||||
|
|
||||||
BOOST_BEAST_DECL
|
BOOST_BEAST_DECL
|
||||||
void
|
void
|
||||||
append(string_view sv);
|
append(string_view s);
|
||||||
|
|
||||||
BOOST_BEAST_DECL
|
BOOST_BEAST_DECL
|
||||||
void
|
void
|
||||||
append(string_view sv1, string_view sv2);
|
append(string_view s1, string_view s2);
|
||||||
|
|
||||||
string_view
|
string_view
|
||||||
view() const noexcept
|
view() const noexcept
|
||||||
@@ -57,11 +53,11 @@ struct temporary_buffer
|
|||||||
private:
|
private:
|
||||||
BOOST_BEAST_DECL
|
BOOST_BEAST_DECL
|
||||||
void
|
void
|
||||||
unchecked_append(string_view sv);
|
unchecked_append(string_view s);
|
||||||
|
|
||||||
BOOST_BEAST_DECL
|
BOOST_BEAST_DECL
|
||||||
void
|
void
|
||||||
grow(std::size_t sv_size);
|
grow(std::size_t n);
|
||||||
|
|
||||||
void
|
void
|
||||||
deallocate(char* data) noexcept
|
deallocate(char* data) noexcept
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#define BOOST_BEAST_IMPL_STRING_IPP
|
#define BOOST_BEAST_IMPL_STRING_IPP
|
||||||
|
|
||||||
#include <boost/beast/core/string.hpp>
|
#include <boost/beast/core/string.hpp>
|
||||||
|
#include <boost/beast/core/detail/string.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@@ -40,7 +41,8 @@ iequals(
|
|||||||
slow:
|
slow:
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if(detail::ascii_tolower(a) != detail::ascii_tolower(b))
|
if( detail::ascii_tolower(a) !=
|
||||||
|
detail::ascii_tolower(b))
|
||||||
return false;
|
return false;
|
||||||
a = *p1++;
|
a = *p1++;
|
||||||
b = *p2++;
|
b = *p2++;
|
||||||
@@ -51,8 +53,8 @@ slow:
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
iless::operator()(
|
iless::operator()(
|
||||||
string_view lhs,
|
string_view lhs,
|
||||||
string_view rhs) const
|
string_view rhs) const
|
||||||
{
|
{
|
||||||
using std::begin;
|
using std::begin;
|
||||||
using std::end;
|
using std::end;
|
||||||
|
@@ -10,18 +10,12 @@
|
|||||||
#ifndef BOOST_BEAST_STRING_HPP
|
#ifndef BOOST_BEAST_STRING_HPP
|
||||||
#define 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 boost {
|
||||||
namespace beast {
|
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.
|
/** Returns `true` if two strings are equal, using a case-insensitive comparison.
|
||||||
|
|
||||||
The case-comparison operation is defined only for low-ASCII characters.
|
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