LCOV - code coverage report
Current view: top level - boost/capy/buffers - to_string.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 88.9 % 9 8
Test Date: 2026-01-15 18:27:21 Functions: 100.0 % 3 3

            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/capy
       8              : //
       9              : 
      10              : #ifndef BOOST_CAPY_BUFFERS_TO_STRING_HPP
      11              : #define BOOST_CAPY_BUFFERS_TO_STRING_HPP
      12              : 
      13              : #include <boost/capy/detail/config.hpp>
      14              : #include <boost/capy/buffers.hpp>
      15              : #include <string>
      16              : 
      17              : namespace boost {
      18              : namespace capy {
      19              : 
      20              : /** Convert a buffer sequence to a string
      21              : 
      22              :     This function constructs a string from the bytes in the
      23              :     buffer sequence `bs`.
      24              : 
      25              :     @par Constraints
      26              :     @code
      27              :     const_buffer_sequence<ConstBufferSequence>
      28              :     @endcode
      29              : 
      30              :     @param bs The buffer sequence
      31              : 
      32              :     @return A string holding the bytes from the buffer sequence
      33              : */
      34              : template<const_buffer_sequence ConstBufferSequence>
      35              : std::string
      36           55 : to_string(ConstBufferSequence const& bs)
      37              : {
      38           55 :     std::string s;
      39           55 :     auto const e = end(bs);
      40          395 :     for(auto it = begin(bs); it != e; ++it)
      41              :     {
      42          340 :         const_buffer b(*it);
      43          680 :         s.append(
      44          340 :             static_cast<char const*>(b.data()),
      45              :             b.size());
      46              :     }
      47           71 :     return s;
      48            0 : }
      49              : 
      50              : } // capy
      51              : } // boost
      52              : 
      53              : #endif
        

Generated by: LCOV version 2.3