GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/parse.ipp
Date: 2025-12-23 17:20:53
Exec Total Coverage
Lines: 49 51 96.1%
Functions: 6 6 100.0%
Branches: 28 30 93.3%

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_IPP
12 #define BOOST_JSON_IMPL_PARSE_IPP
13
14 #include <boost/json/parse.hpp>
15 #include <boost/json/parser.hpp>
16 #include <boost/json/detail/except.hpp>
17
18 #include <istream>
19
20 namespace boost {
21 namespace json {
22
23 value
24 2001505 parse(
25 string_view s,
26 system::error_code& ec,
27 storage_ptr sp,
28 const parse_options& opt)
29 {
30 unsigned char temp[
31 BOOST_JSON_STACK_BUFFER_SIZE];
32 2001505 parser p(storage_ptr(), opt, temp);
33 2001505 p.reset(std::move(sp));
34
1/1
✓ Branch 1 taken 2001502 times.
2001505 p.write(s, ec);
35
2/2
✓ Branch 1 taken 15 times.
✓ Branch 2 taken 2001489 times.
2001504 if(ec)
36 15 return nullptr;
37
1/1
✓ Branch 1 taken 2001488 times.
2001489 return p.release();
38 2001505 }
39
40 value
41 4 parse(
42 string_view s,
43 std::error_code& ec,
44 storage_ptr sp,
45 parse_options const& opt)
46 {
47 4 system::error_code jec;
48
1/1
✓ Branch 3 taken 4 times.
4 value result = parse(s, jec, std::move(sp), opt);
49
1/1
✓ Branch 1 taken 4 times.
4 ec = jec;
50 8 return result;
51 }
52
53 value
54 2001038 parse(
55 string_view s,
56 storage_ptr sp,
57 const parse_options& opt)
58 {
59 2001038 system::error_code ec;
60 auto jv = parse(
61
1/1
✓ Branch 3 taken 2001037 times.
2001039 s, ec, std::move(sp), opt);
62
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2001035 times.
2001037 if(ec)
63 2 detail::throw_system_error( ec );
64 4002070 return jv;
65 2 }
66
67 value
68 10 parse(
69 std::istream& is,
70 system::error_code& ec,
71 storage_ptr sp,
72 parse_options const& opt)
73 {
74 unsigned char parser_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2];
75 10 stream_parser p(storage_ptr(), opt, parser_buffer);
76 10 p.reset(std::move(sp));
77
78 char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2];
79 do
80 {
81
3/4
✓ Branch 1 taken 17 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 10 times.
✗ Branch 2 not taken.
17 if( is.eof() )
82 {
83
1/1
✓ Branch 1 taken 7 times.
7 p.finish(ec);
84 7 break;
85 }
86
87
3/4
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 9 times.
✗ Branch 2 not taken.
10 if( !is )
88 {
89 1 BOOST_JSON_FAIL( ec, error::input_error );
90 1 break;
91 }
92
93
1/1
✓ Branch 1 taken 9 times.
9 is.read(read_buffer, sizeof(read_buffer));
94 9 auto const consumed = is.gcount();
95
96
1/1
✓ Branch 1 taken 9 times.
9 p.write( read_buffer, static_cast<std::size_t>(consumed), ec );
97 }
98
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
9 while( !ec.failed() );
99
100
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 7 times.
10 if( ec.failed() )
101 3 return nullptr;
102
103
1/1
✓ Branch 1 taken 7 times.
7 return p.release();
104 10 }
105
106 value
107 4 parse(
108 std::istream& is,
109 std::error_code& ec,
110 storage_ptr sp,
111 parse_options const& opt)
112 {
113 4 system::error_code jec;
114
1/1
✓ Branch 3 taken 4 times.
4 value result = parse(is, jec, std::move(sp), opt);
115
1/1
✓ Branch 1 taken 4 times.
4 ec = jec;
116 8 return result;
117 }
118
119 value
120 2 parse(
121 std::istream& is,
122 storage_ptr sp,
123 parse_options const& opt)
124 {
125 2 system::error_code ec;
126 auto jv = parse(
127
1/1
✓ Branch 3 taken 2 times.
2 is, ec, std::move(sp), opt);
128
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
2 if(ec)
129 1 detail::throw_system_error( ec );
130 2 return jv;
131 1 }
132
133 } // namespace json
134 } // namespace boost
135
136 #endif
137