91.67% Lines (11/12)
100.00% Functions (2/2)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/capy | 7 | // Official repository: https://github.com/cppalliance/capy | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_CAPY_TEST_BUFFER_TO_STRING_HPP | 10 | #ifndef BOOST_CAPY_TEST_BUFFER_TO_STRING_HPP | |||||
| 11 | #define BOOST_CAPY_TEST_BUFFER_TO_STRING_HPP | 11 | #define BOOST_CAPY_TEST_BUFFER_TO_STRING_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/capy/detail/config.hpp> | 13 | #include <boost/capy/detail/config.hpp> | |||||
| 14 | #include <boost/capy/buffers.hpp> | 14 | #include <boost/capy/buffers.hpp> | |||||
| 15 | 15 | |||||||
| 16 | #include <string> | 16 | #include <string> | |||||
| 17 | 17 | |||||||
| 18 | namespace boost { | 18 | namespace boost { | |||||
| 19 | namespace capy { | 19 | namespace capy { | |||||
| 20 | namespace test { | 20 | namespace test { | |||||
| 21 | 21 | |||||||
| 22 | /** Convert one or more buffer sequences to a string. | 22 | /** Convert one or more buffer sequences to a string. | |||||
| 23 | 23 | |||||||
| 24 | This function concatenates the bytes from all provided buffer | 24 | This function concatenates the bytes from all provided buffer | |||||
| 25 | sequences into a single string. With a single argument, it | 25 | sequences into a single string. With a single argument, it | |||||
| 26 | converts that buffer sequence to a string. With multiple | 26 | converts that buffer sequence to a string. With multiple | |||||
| 27 | arguments, it concatenates them in order. | 27 | arguments, it concatenates them in order. | |||||
| 28 | 28 | |||||||
| 29 | + | @par Exception Safety | ||||||
| 30 | + | Strong guarantee. | ||||||
| 31 | + | |||||||
| 32 | + | @throws std::bad_alloc If memory allocation fails. | ||||||
| 33 | + | |||||||
| 29 | @par Example | 34 | @par Example | |||||
| 30 | @par !example example | 35 | @par !example example | |||||
| 31 | 36 | |||||||
| 32 | 37 | |||||||
| 33 | @param bufs One or more buffer sequences to concatenate. | 38 | @param bufs One or more buffer sequences to concatenate. | |||||
| 34 | 39 | |||||||
| 35 | @return A string containing all bytes from the buffer sequences. | 40 | @return A string containing all bytes from the buffer sequences. | |||||
| 36 | */ | 41 | */ | |||||
| 37 | template<ConstBufferSequence... Buffers> | 42 | template<ConstBufferSequence... Buffers> | |||||
| 38 | std::string | 43 | std::string | |||||
| HITCBC | 39 | 176 | buffer_to_string(Buffers const&... bufs) | 44 | 176 | buffer_to_string(Buffers const&... bufs) | ||
| 40 | { | 45 | { | |||||
| HITCBC | 41 | 176 | std::string result; | 46 | 176 | std::string result; | ||
| HITCBC | 42 | 176 | result.reserve((buffer_size(bufs) + ...)); | 47 | 176 | result.reserve((buffer_size(bufs) + ...)); | ||
| HITCBC | 43 | 488 | auto append = [&](auto const& bs) { | 48 | 488 | auto append = [&](auto const& bs) { | ||
| HITCBC | 44 | 312 | auto const e = buffer_sequence_end(bs); | 49 | 312 | auto const e = buffer_sequence_end(bs); | ||
| HITCBC | 45 | 634 | for(auto it = buffer_sequence_begin(bs); it != e; ++it) | 50 | 634 | for(auto it = buffer_sequence_begin(bs); it != e; ++it) | ||
| 46 | { | 51 | { | |||||
| HITCBC | 47 | 319 | const_buffer b(*it); | 52 | 319 | const_buffer b(*it); | ||
| HITCBC | 48 | 644 | result.append( | 53 | 644 | result.append( | ||
| HITCBC | 49 | 322 | static_cast<char const*>(b.data()), | 54 | 322 | static_cast<char const*>(b.data()), | ||
| 50 | b.size()); | 55 | b.size()); | |||||
| 51 | } | 56 | } | |||||
| 52 | }; | 57 | }; | |||||
| HITCBC | 53 | 176 | (append(bufs), ...); | 58 | 176 | (append(bufs), ...); | ||
| HITCBC | 54 | 352 | return result; | 59 | 352 | return result; | ||
| MISUBC | 55 | ✗ | } | 60 | ✗ | } | ||
| 56 | 61 | |||||||
| 57 | } // test | 62 | } // test | |||||
| 58 | } // capy | 63 | } // capy | |||||
| 59 | } // boost | 64 | } // boost | |||||
| 60 | 65 | |||||||
| 61 | #endif | 66 | #endif | |||||