GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/parse_into.hpp
Date: 2025-12-23 17:20:53
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 296 296 100.0%
Branches: 36 36 100.0%

Line Branch Exec Source
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 493 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
1/1
✓ Branch 1 taken 247 times.
493 parser_for<V, Ctx> p(opt, &v, ctx);
31
1/1
✓ Branch 3 taken 247 times.
493 std::size_t n = p.write_some(false, sv.data(), sv.size(), ec);
32
6/6
✓ Branch 1 taken 223 times.
✓ Branch 2 taken 24 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 222 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 246 times.
493 if( !ec && n < sv.size() )
33 {
34 2 BOOST_JSON_FAIL(ec, error::extra_data);
35 }
36 493 }
37
38 template< class V, class Ctx >
39 void
40 142 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 142 system::error_code jec;
48
1/1
✓ Branch 1 taken 71 times.
142 parse_into(v, sv, jec, opt, ctx);
49
1/1
✓ Branch 1 taken 71 times.
142 ec = jec;
50 142 }
51
52 template< class V, class Ctx >
53 void
54 157 parse_into(
55 V& v,
56 string_view sv,
57 parse_options const& opt,
58 Ctx const& ctx )
59 {
60 157 system::error_code ec;
61
1/1
✓ Branch 1 taken 79 times.
157 parse_into(v, sv, ec, opt, ctx);
62
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 78 times.
157 if( ec.failed() )
63 2 detail::throw_system_error( ec );
64 155 }
65
66 template< class V, class Ctx >
67 void
68 432 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
1/1
✓ Branch 1 taken 216 times.
432 parser_for<V, Ctx> p(opt, &v, ctx);
76
77 char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE];
78 do
79 {
80
3/3
✓ Branch 1 taken 429 times.
✓ Branch 3 taken 213 times.
✓ Branch 4 taken 216 times.
858 if( is.eof() )
81 {
82
1/1
✓ Branch 1 taken 213 times.
426 p.write_some(false, nullptr, 0, ec);
83 426 break;
84 }
85
86
3/3
✓ Branch 1 taken 216 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 215 times.
432 if( !is )
87 {
88 2 BOOST_JSON_FAIL( ec, error::input_error );
89 2 break;
90 }
91
92
1/1
✓ Branch 1 taken 215 times.
430 is.read(read_buffer, sizeof(read_buffer));
93 430 std::size_t const consumed = static_cast<std::size_t>( is.gcount() );
94
95
1/1
✓ Branch 1 taken 215 times.
430 std::size_t const n = p.write_some( true, read_buffer, consumed, ec );
96
6/6
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 213 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 214 times.
430 if( !ec.failed() && n < consumed )
97 {
98 2 BOOST_JSON_FAIL( ec, error::extra_data );
99 }
100 }
101
2/2
✓ Branch 1 taken 213 times.
✓ Branch 2 taken 2 times.
430 while( !ec.failed() );
102 432 }
103
104 template< class V, class Ctx >
105 void
106 142 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 142 system::error_code jec;
114
1/1
✓ Branch 1 taken 71 times.
142 parse_into(v, is, jec, opt, ctx);
115
1/1
✓ Branch 1 taken 71 times.
142 ec = jec;
116 142 }
117
118 template< class V, class Ctx >
119 void
120 144 parse_into(
121 V& v,
122 std::istream& is,
123 parse_options const& opt,
124 Ctx const& ctx )
125 {
126 144 system::error_code ec;
127
1/1
✓ Branch 1 taken 72 times.
144 parse_into(v, is, ec, opt, ctx);
128
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 71 times.
144 if( ec.failed() )
129 2 detail::throw_system_error( ec );
130 142 }
131
132 } // namespace boost
133 } // namespace json
134
135 #endif
136