impl/parse_into.hpp

100.0% Lines (43/43) 100.0% Functions (266/266) 100.0% Branches (36/36)
impl/parse_into.hpp
Line Branch Hits 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>
22 void
23 232 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.
232 parser_for<V> p( opt, &v );
30
31
1/1
✓ Branch 3 taken 232 times.
232 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 time.
✓ Branch 5 taken 207 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 231 times.
232 if( !ec && n < sv.size() )
34 {
35 1 BOOST_JSON_FAIL( ec, error::extra_data );
36 }
37 232 }
38
39 template<class V>
40 void
41 66 parse_into(
42 V& v,
43 string_view sv,
44 std::error_code& ec,
45 parse_options const& opt )
46 {
47 66 system::error_code jec;
48
1/1
✓ Branch 1 taken 66 times.
66 parse_into(v, sv, jec, opt);
49
1/1
✓ Branch 1 taken 66 times.
66 ec = jec;
50 66 }
51
52 template<class V>
53 void
54 74 parse_into(
55 V& v,
56 string_view sv,
57 parse_options const& opt )
58 {
59 74 system::error_code ec;
60
1/1
✓ Branch 1 taken 74 times.
74 parse_into(v, sv, ec, opt);
61
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 73 times.
74 if( ec.failed() )
62 1 detail::throw_system_error( ec );
63 73 }
64
65 template<class V>
66 void
67 201 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.
201 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.
399 if( is.eof() )
79 {
80
1/1
✓ Branch 1 taken 198 times.
198 p.write_some(false, nullptr, 0, ec);
81 198 break;
82 }
83
84
3/3
✓ Branch 1 taken 201 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 200 times.
201 if( !is )
85 {
86 1 BOOST_JSON_FAIL( ec, error::input_error );
87 1 break;
88 }
89
90
1/1
✓ Branch 1 taken 200 times.
200 is.read(read_buffer, sizeof(read_buffer));
91 200 std::size_t const consumed = static_cast<std::size_t>( is.gcount() );
92
93
1/1
✓ Branch 1 taken 200 times.
200 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 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 198 times.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 199 times.
200 if( !ec.failed() && n < consumed )
95 {
96 1 BOOST_JSON_FAIL( ec, error::extra_data );
97 }
98 }
99
2/2
✓ Branch 1 taken 198 times.
✓ Branch 2 taken 2 times.
200 while( !ec.failed() );
100 201 }
101
102 template<class V>
103 void
104 66 parse_into(
105 V& v,
106 std::istream& is,
107 std::error_code& ec,
108 parse_options const& opt )
109 {
110 66 system::error_code jec;
111
1/1
✓ Branch 1 taken 66 times.
66 parse_into(v, is, jec, opt);
112
1/1
✓ Branch 1 taken 66 times.
66 ec = jec;
113 66 }
114
115 template<class V>
116 void
117 67 parse_into(
118 V& v,
119 std::istream& is,
120 parse_options const& opt )
121 {
122 67 system::error_code ec;
123
1/1
✓ Branch 1 taken 67 times.
67 parse_into(v, is, ec, opt);
124
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 66 times.
67 if( ec.failed() )
125 1 detail::throw_system_error( ec );
126 66 }
127
128 } // namespace boost
129 } // namespace json
130
131 #endif
132