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