LCOV - code coverage report
Current view: top level - boost/buffers - to_string.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 9 9
Test Date: 2025-12-06 02:12:43 Functions: 100.0 % 6 6

            Line data    Source code
       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           85 : to_string(ConstBufferSequence const& bs)
      34              : {
      35              :     BOOST_CORE_STATIC_ASSERT(
      36              :         is_const_buffer_sequence<ConstBufferSequence>::value);
      37           85 :     std::string s;
      38           85 :     auto const e = end(bs);
      39          452 :     for(auto it = begin(bs); it != e; ++it)
      40              :     {
      41          367 :         const_buffer b(*it);
      42          734 :         s.append(
      43          367 :             static_cast<char const*>(b.data()),
      44              :             b.size());
      45              :     }
      46          124 :     return s;
      47           23 : }
      48              : 
      49              : } // buffers
      50              : } // boost
      51              : 
      52              : #endif
        

Generated by: LCOV version 2.1