Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:27

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_BUFFERS_TO_STRING_HPP
0011 #define BOOST_BEAST_BUFFERS_TO_STRING_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/core/buffer_traits.hpp>
0015 #include <boost/beast/core/buffers_range.hpp>
0016 #include <boost/asio/buffer.hpp>
0017 #include <string>
0018 
0019 namespace boost {
0020 namespace beast {
0021 
0022 /** Return a string representing the contents of a buffer sequence.
0023 
0024     This function returns a string representing an entire buffer
0025     sequence. Nulls and unprintable characters in the buffer
0026     sequence are inserted to the resulting string as-is. No
0027     character conversions are performed.
0028 
0029     @param buffers The buffer sequence to convert
0030 
0031     @par Example
0032 
0033     This function writes a buffer sequence converted to a string
0034     to `std::cout`.
0035 
0036     @code
0037     template<class ConstBufferSequence>
0038     void print(ConstBufferSequence const& buffers)
0039     {
0040         std::cout << buffers_to_string(buffers) << std::endl;
0041     }
0042     @endcode
0043 */
0044 template<class ConstBufferSequence>
0045 std::string
0046 buffers_to_string(ConstBufferSequence const& buffers)
0047 {
0048     static_assert(
0049         net::is_const_buffer_sequence<ConstBufferSequence>::value,
0050         "ConstBufferSequence type requirements not met");
0051     std::string result;
0052     result.reserve(buffer_bytes(buffers));
0053     for(auto const buffer : buffers_range_ref(buffers))
0054         result.append(static_cast<char const*>(
0055             buffer.data()), buffer.size());
0056     return result;
0057 }
0058 
0059 } // beast
0060 } // boost
0061 
0062 #endif