GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/stream_parser.ipp
Date: 2025-12-23 17:20:53
Exec Total Coverage
Lines: 67 67 100.0%
Functions: 13 13 100.0%
Branches: 23 23 100.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 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/boostorg/json
8 //
9
10 #ifndef BOOST_JSON_IMPL_STREAM_PARSER_IPP
11 #define BOOST_JSON_IMPL_STREAM_PARSER_IPP
12
13 #include <boost/json/stream_parser.hpp>
14 #include <boost/json/basic_parser_impl.hpp>
15 #include <boost/json/error.hpp>
16 #include <cstring>
17 #include <stdexcept>
18 #include <utility>
19
20 namespace boost {
21 namespace json {
22
23 22 stream_parser::
24 stream_parser(
25 storage_ptr sp,
26 parse_options const& opt,
27 unsigned char* buffer,
28 22 std::size_t size) noexcept
29 22 : p_(
30 opt,
31 22 std::move(sp),
32 buffer,
33 size)
34 {
35 22 reset();
36 22 }
37
38 75304 stream_parser::
39 stream_parser(
40 storage_ptr sp,
41 75304 parse_options const& opt) noexcept
42 75304 : p_(
43 opt,
44 75304 std::move(sp),
45 150608 nullptr,
46 75304 0)
47 {
48 75304 reset();
49 75304 }
50
51 void
52 150055 stream_parser::
53 reset(storage_ptr sp) noexcept
54 {
55 150055 p_.reset();
56 150055 p_.handler().st.reset(sp);
57 150055 }
58
59 std::size_t
60 130421 stream_parser::
61 write_some(
62 char const* data,
63 std::size_t size,
64 system::error_code& ec)
65 {
66 130421 return p_.write_some(
67 130280 true, data, size, ec);
68 }
69
70 std::size_t
71 2 stream_parser::
72 write_some(
73 char const* data,
74 std::size_t size,
75 std::error_code& ec)
76 {
77 2 system::error_code jec;
78
1/1
✓ Branch 1 taken 2 times.
2 std::size_t const result = write_some(data, size, jec);
79
1/1
✓ Branch 1 taken 2 times.
2 ec = jec;
80 2 return result;
81 }
82
83 std::size_t
84 6 stream_parser::
85 write_some(
86 char const* data,
87 std::size_t size)
88 {
89 6 system::error_code ec;
90
1/1
✓ Branch 1 taken 6 times.
6 auto const n = write_some(
91 data, size, ec);
92
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
6 if(ec)
93 1 detail::throw_system_error( ec );
94 5 return n;
95 }
96
97 std::size_t
98 130392 stream_parser::
99 write(
100 char const* data,
101 std::size_t size,
102 system::error_code& ec)
103 {
104 130392 auto const n = write_some(
105 data, size, ec);
106
6/6
✓ Branch 1 taken 130249 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 130243 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 130245 times.
130251 if(! ec && n < size)
107 {
108 6 BOOST_JSON_FAIL(ec, error::extra_data);
109 6 p_.fail(ec);
110 }
111 130251 return n;
112 }
113
114 std::size_t
115 2 stream_parser::
116 write(
117 char const* data,
118 std::size_t size,
119 std::error_code& ec)
120 {
121 2 system::error_code jec;
122
1/1
✓ Branch 1 taken 2 times.
2 std::size_t const result = write(data, size, jec);
123
1/1
✓ Branch 1 taken 2 times.
2 ec = jec;
124 2 return result;
125 }
126
127 std::size_t
128 11 stream_parser::
129 write(
130 char const* data,
131 std::size_t size)
132 {
133 11 system::error_code ec;
134
1/1
✓ Branch 1 taken 11 times.
11 auto const n = write(
135 data, size, ec);
136
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
11 if(ec)
137 1 detail::throw_system_error( ec );
138 10 return n;
139 }
140
141 void
142 75152 stream_parser::
143 finish(system::error_code& ec)
144 {
145 75152 p_.write_some(false, nullptr, 0, ec);
146 75152 }
147
148 void
149 8 stream_parser::
150 finish()
151 {
152 8 system::error_code ec;
153
1/1
✓ Branch 1 taken 8 times.
8 finish(ec);
154
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
8 if(ec)
155 6 detail::throw_system_error( ec );
156 2 }
157
158 void
159 2 stream_parser::
160 finish(std::error_code& ec)
161 {
162 2 system::error_code jec;
163
1/1
✓ Branch 1 taken 2 times.
2 finish(jec);
164
1/1
✓ Branch 1 taken 2 times.
2 ec = jec;
165 2 }
166
167 value
168 75151 stream_parser::
169 release()
170 {
171
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 75147 times.
75151 if(! p_.done())
172 {
173 // prevent undefined behavior
174 4 finish();
175 }
176 75148 return p_.handler().st.release();
177 }
178
179 } // namespace json
180 } // namespace boost
181
182 #endif
183