GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/parse_into.hpp
Date: 2025-12-23 17:15:02
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 266 266 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>
22 void
23 463 parse_into(
24 V& v,
25 string_view sv,
26 system::error_code& ec,
27 parse_options const& opt )
28 {
29
1/1
✓ Branch 1 taken 232 times.
463 parser_for<V> p( opt, &v );
30
31
1/1
✓ Branch 3 taken 232 times.
463 std::size_t n = p.write_some( false, sv.data(), sv.size(), ec );
32
33
6/6
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 24 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 207 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 231 times.
463 if( !ec && n < sv.size() )
34 {
35 2 BOOST_JSON_FAIL( ec, error::extra_data );
36 }
37 463 }
38
39 template<class V>
40 void
41 132 parse_into(
42 V& v,
43 string_view sv,
44 std::error_code& ec,
45 parse_options const& opt )
46 {
47 132 system::error_code jec;
48
1/1
✓ Branch 1 taken 66 times.
132 parse_into(v, sv, jec, opt);
49
1/1
✓ Branch 1 taken 66 times.
132 ec = jec;
50 132 }
51
52 template<class V>
53 void
54 147 parse_into(
55 V& v,
56 string_view sv,
57 parse_options const& opt )
58 {
59 147 system::error_code ec;
60
1/1
✓ Branch 1 taken 74 times.
147 parse_into(v, sv, ec, opt);
61
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 73 times.
147 if( ec.failed() )
62 2 detail::throw_system_error( ec );
63 145 }
64
65 template<class V>
66 void
67 402 parse_into(
68 V& v,
69 std::istream& is,
70 system::error_code& ec,
71 parse_options const& opt )
72 {
73
1/1
✓ Branch 1 taken 201 times.
402 parser_for<V> p( opt, &v );
74
75 char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE];
76 do
77 {
78
3/3
✓ Branch 1 taken 399 times.
✓ Branch 3 taken 198 times.
✓ Branch 4 taken 201 times.
798 if( is.eof() )
79 {
80
1/1
✓ Branch 1 taken 198 times.
396 p.write_some(false, nullptr, 0, ec);
81 396 break;
82 }
83
84
3/3
✓ Branch 1 taken 201 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 200 times.
402 if( !is )
85 {
86 2 BOOST_JSON_FAIL( ec, error::input_error );
87 2 break;
88 }
89
90
1/1
✓ Branch 1 taken 200 times.
400 is.read(read_buffer, sizeof(read_buffer));
91 400 std::size_t const consumed = static_cast<std::size_t>( is.gcount() );
92
93
1/1
✓ Branch 1 taken 200 times.
400 std::size_t const n = p.write_some( true, read_buffer, consumed, ec );
94
6/6
✓ Branch 1 taken 199 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 198 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 199 times.
400 if( !ec.failed() && n < consumed )
95 {
96 2 BOOST_JSON_FAIL( ec, error::extra_data );
97 }
98 }
99
2/2
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 2 times.
400 while( !ec.failed() );
100 402 }
101
102 template<class V>
103 void
104 132 parse_into(
105 V& v,
106 std::istream& is,
107 std::error_code& ec,
108 parse_options const& opt )
109 {
110 132 system::error_code jec;
111
1/1
✓ Branch 1 taken 66 times.
132 parse_into(v, is, jec, opt);
112
1/1
✓ Branch 1 taken 66 times.
132 ec = jec;
113 132 }
114
115 template<class V>
116 void
117 134 parse_into(
118 V& v,
119 std::istream& is,
120 parse_options const& opt )
121 {
122 134 system::error_code ec;
123
1/1
✓ Branch 1 taken 67 times.
134 parse_into(v, is, ec, opt);
124
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 66 times.
134 if( ec.failed() )
125 2 detail::throw_system_error( ec );
126 132 }
127
128 } // namespace boost
129 } // namespace json
130
131 #endif
132