LCOV - code coverage report
Current view: top level - json/impl - parse_into.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 43 43
Test Date: 2026-03-05 09:04:27 Functions: 100.0 % 296 296

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3                 : // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
       4                 : //
       5                 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       6                 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       7                 : //
       8                 : // Official repository: https://github.com/boostorg/json
       9                 : //
      10                 : 
      11                 : #ifndef BOOST_JSON_IMPL_PARSE_INTO_HPP
      12                 : #define BOOST_JSON_IMPL_PARSE_INTO_HPP
      13                 : 
      14                 : #include <boost/json/basic_parser_impl.hpp>
      15                 : #include <boost/json/error.hpp>
      16                 : #include <istream>
      17                 : 
      18                 : namespace boost {
      19                 : namespace json {
      20                 : 
      21                 : template< class V, class Ctx >
      22                 : void
      23 HIT         247 : parse_into(
      24                 :     V& v,
      25                 :     string_view sv,
      26                 :     system::error_code& ec,
      27                 :     parse_options const& opt,
      28                 :     Ctx const& ctx )
      29                 : {
      30             247 :     parser_for<V, Ctx> p(opt, &v, ctx);
      31             247 :     std::size_t n = p.write_some(false, sv.data(), sv.size(), ec);
      32             247 :     if( !ec && n < sv.size() )
      33                 :     {
      34               1 :         BOOST_JSON_FAIL(ec, error::extra_data);
      35                 :     }
      36             247 : }
      37                 : 
      38                 : template< class V, class Ctx >
      39                 : void
      40              71 : parse_into(
      41                 :     V& v,
      42                 :     string_view sv,
      43                 :     std::error_code& ec,
      44                 :     parse_options const& opt,
      45                 :     Ctx const& ctx )
      46                 : {
      47              71 :     system::error_code jec;
      48              71 :     parse_into(v, sv, jec, opt, ctx);
      49              71 :     ec = jec;
      50              71 : }
      51                 : 
      52                 : template< class V, class Ctx >
      53                 : void
      54              79 : parse_into(
      55                 :     V& v,
      56                 :     string_view sv,
      57                 :     parse_options const& opt,
      58                 :     Ctx const& ctx )
      59                 : {
      60              79 :     system::error_code ec;
      61              79 :     parse_into(v, sv, ec, opt, ctx);
      62              79 :     if( ec.failed() )
      63               1 :         detail::throw_system_error( ec );
      64              78 : }
      65                 : 
      66                 : template< class V, class Ctx >
      67                 : void
      68             216 : parse_into(
      69                 :     V& v,
      70                 :     std::istream& is,
      71                 :     system::error_code& ec,
      72                 :     parse_options const& opt,
      73                 :     Ctx const& ctx )
      74                 : {
      75             216 :     parser_for<V, Ctx> p(opt, &v, ctx);
      76                 : 
      77                 :     char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE];
      78                 :     do
      79                 :     {
      80             429 :         if( is.eof() )
      81                 :         {
      82             213 :             p.write_some(false, nullptr, 0, ec);
      83             213 :             break;
      84                 :         }
      85                 : 
      86             216 :         if( !is )
      87                 :         {
      88               1 :             BOOST_JSON_FAIL( ec, error::input_error );
      89               1 :             break;
      90                 :         }
      91                 : 
      92             215 :         is.read(read_buffer, sizeof(read_buffer));
      93             215 :         std::size_t const consumed = static_cast<std::size_t>( is.gcount() );
      94                 : 
      95             215 :         std::size_t const n = p.write_some( true, read_buffer, consumed, ec );
      96             215 :         if( !ec.failed() && n < consumed )
      97                 :         {
      98               1 :             BOOST_JSON_FAIL( ec, error::extra_data );
      99                 :         }
     100                 :     }
     101             215 :     while( !ec.failed() );
     102             216 : }
     103                 : 
     104                 : template< class V, class Ctx >
     105                 : void
     106              71 : parse_into(
     107                 :     V& v,
     108                 :     std::istream& is,
     109                 :     std::error_code& ec,
     110                 :     parse_options const& opt,
     111                 :     Ctx const& ctx )
     112                 : {
     113              71 :     system::error_code jec;
     114              71 :     parse_into(v, is, jec, opt, ctx);
     115              71 :     ec = jec;
     116              71 : }
     117                 : 
     118                 : template< class V, class Ctx >
     119                 : void
     120              72 : parse_into(
     121                 :     V& v,
     122                 :     std::istream& is,
     123                 :     parse_options const& opt,
     124                 :     Ctx const& ctx )
     125                 : {
     126              72 :     system::error_code ec;
     127              72 :     parse_into(v, is, ec, opt, ctx);
     128              72 :     if( ec.failed() )
     129               1 :         detail::throw_system_error( ec );
     130              71 : }
     131                 : 
     132                 : } // namespace boost
     133                 : } // namespace json
     134                 : 
     135                 : #endif
        

Generated by: LCOV version 2.3