| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/buffers | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_BUFFERS_TO_STRING_HPP | ||
| 11 | #define BOOST_BUFFERS_TO_STRING_HPP | ||
| 12 | |||
| 13 | #include <boost/buffers/detail/config.hpp> | ||
| 14 | #include <boost/buffers/buffer.hpp> | ||
| 15 | #include <boost/core/detail/static_assert.hpp> | ||
| 16 | #include <string> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace buffers { | ||
| 20 | |||
| 21 | /** Convert a buffer sequence to a string | ||
| 22 | This function constructs a string from the bytes in the | ||
| 23 | buffer sequence `bs`. | ||
| 24 | @par Constraints | ||
| 25 | @code | ||
| 26 | requires is_const_buffer_sequence<BufferSequence>::value | ||
| 27 | @endcode | ||
| 28 | @param bs The buffer sequence | ||
| 29 | @return A string holding the bytes from the buffer sequence | ||
| 30 | */ | ||
| 31 | template< class ConstBufferSequence > | ||
| 32 | std::string | ||
| 33 | 169 | to_string(ConstBufferSequence const& bs) | |
| 34 | { | ||
| 35 | BOOST_CORE_STATIC_ASSERT( | ||
| 36 | is_const_buffer_sequence<ConstBufferSequence>::value); | ||
| 37 | 169 | std::string s; | |
| 38 | 169 | auto const e = end(bs); | |
| 39 |
4/4✓ Branch 1 taken 50 times.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 317 times.
✓ Branch 4 taken 39 times.
|
902 | for(auto it = begin(bs); it != e; ++it) |
| 40 | { | ||
| 41 | 733 | const_buffer b(*it); | |
| 42 |
1/1✓ Branch 2 taken 367 times.
|
1466 | s.append( |
| 43 | 733 | static_cast<char const*>(b.data()), | |
| 44 | b.size()); | ||
| 45 | } | ||
| 46 | 247 | return s; | |
| 47 | 46 | } | |
| 48 | |||
| 49 | } // buffers | ||
| 50 | } // boost | ||
| 51 | |||
| 52 | #endif | ||
| 53 |