LCOV - code coverage report
Current view: top level - capy/test - buffer_to_string.hpp (source / functions) Coverage Total Hit Missed
Test: coverage_remapped.info Lines: 91.7 % 12 11 1
Test Date: 2026-08-21 22:12:46 Functions: 100.0 % 10 10

           TLA  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_TEST_BUFFER_TO_STRING_HPP
      11                 : #define BOOST_CAPY_TEST_BUFFER_TO_STRING_HPP
      12                 : 
      13                 : #include <boost/capy/detail/config.hpp>
      14                 : #include <boost/capy/buffers.hpp>
      15                 : 
      16                 : #include <string>
      17                 : 
      18                 : namespace boost {
      19                 : namespace capy {
      20                 : namespace test {
      21                 : 
      22                 : /** Convert one or more buffer sequences to a string.
      23                 : 
      24                 :     This function concatenates the bytes from all provided buffer
      25                 :     sequences into a single string. With a single argument, it
      26                 :     converts that buffer sequence to a string. With multiple
      27                 :     arguments, it concatenates them in order.
      28                 : 
      29                 :     @par Example
      30                 :     @par !example example
      31                 : 
      32                 : 
      33                 :     @param bufs One or more buffer sequences to concatenate.
      34                 : 
      35                 :     @return A string containing all bytes from the buffer sequences.
      36                 : */
      37                 : template<ConstBufferSequence... Buffers>
      38                 : std::string
      39 HIT         176 : buffer_to_string(Buffers const&... bufs)
      40                 : {
      41             176 :     std::string result;
      42             176 :     result.reserve((buffer_size(bufs) + ...));
      43             488 :     auto append = [&](auto const& bs) {
      44             312 :         auto const e = end(bs);
      45             634 :         for(auto it = begin(bs); it != e; ++it)
      46                 :         {
      47             319 :             const_buffer b(*it);
      48             644 :             result.append(
      49             322 :                 static_cast<char const*>(b.data()),
      50                 :                 b.size());
      51                 :         }
      52                 :     };
      53             176 :     (append(bufs), ...);
      54             352 :     return result;
      55 MIS           0 : }
      56                 : 
      57                 : } // test
      58                 : } // capy
      59                 : } // boost
      60                 : 
      61                 : #endif
        

Generated by: LCOV version 2.3