| 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_PARSER_IPP | ||
| 11 | #define BOOST_JSON_IMPL_PARSER_IPP | ||
| 12 | |||
| 13 | #include <boost/json/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 | 2001508 | parser:: | |
| 24 | parser( | ||
| 25 | storage_ptr sp, | ||
| 26 | parse_options const& opt, | ||
| 27 | unsigned char* buffer, | ||
| 28 | 2001508 | std::size_t size) noexcept | |
| 29 | 2001508 | : p_( | |
| 30 | opt, | ||
| 31 | 2001508 | std::move(sp), | |
| 32 | buffer, | ||
| 33 | size) | ||
| 34 | { | ||
| 35 | 2001508 | reset(); | |
| 36 | 2001508 | } | |
| 37 | |||
| 38 | 55 | parser:: | |
| 39 | parser( | ||
| 40 | storage_ptr sp, | ||
| 41 | 55 | parse_options const& opt) noexcept | |
| 42 | 55 | : p_( | |
| 43 | opt, | ||
| 44 | 55 | std::move(sp), | |
| 45 | 110 | nullptr, | |
| 46 | 55 | 0) | |
| 47 | { | ||
| 48 | 55 | reset(); | |
| 49 | 55 | } | |
| 50 | |||
| 51 | void | ||
| 52 | 4003070 | parser:: | |
| 53 | reset(storage_ptr sp) noexcept | ||
| 54 | { | ||
| 55 | 4003070 | p_.reset(); | |
| 56 | 4003070 | p_.handler().st.reset(sp); | |
| 57 | 4003070 | } | |
| 58 | |||
| 59 | std::size_t | ||
| 60 | 2001553 | parser:: | |
| 61 | write_some( | ||
| 62 | char const* data, | ||
| 63 | std::size_t size, | ||
| 64 | system::error_code& ec) | ||
| 65 | { | ||
| 66 | 2001553 | auto const n = p_.write_some( | |
| 67 | false, data, size, ec); | ||
| 68 |
3/4✓ Branch 1 taken 2001521 times.
✓ Branch 2 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2001521 times.
|
2001552 | BOOST_ASSERT(ec || p_.done()); |
| 69 | 2001552 | return n; | |
| 70 | } | ||
| 71 | |||
| 72 | std::size_t | ||
| 73 | 6 | parser:: | |
| 74 | write_some( | ||
| 75 | char const* data, | ||
| 76 | std::size_t size, | ||
| 77 | std::error_code& ec) | ||
| 78 | { | ||
| 79 | 6 | system::error_code jec; | |
| 80 |
1/1✓ Branch 1 taken 6 times.
|
6 | std::size_t const result = write_some(data, size, jec); |
| 81 |
1/1✓ Branch 1 taken 6 times.
|
6 | ec = jec; |
| 82 | 6 | return result; | |
| 83 | } | ||
| 84 | |||
| 85 | std::size_t | ||
| 86 | 8 | parser:: | |
| 87 | write_some( | ||
| 88 | char const* data, | ||
| 89 | std::size_t size) | ||
| 90 | { | ||
| 91 | 8 | system::error_code ec; | |
| 92 |
1/1✓ Branch 1 taken 8 times.
|
8 | auto const n = write_some( |
| 93 | data, size, ec); | ||
| 94 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
|
8 | if(ec) |
| 95 | 4 | detail::throw_system_error( ec ); | |
| 96 | 4 | return n; | |
| 97 | } | ||
| 98 | |||
| 99 | std::size_t | ||
| 100 | 2001533 | parser:: | |
| 101 | write( | ||
| 102 | char const* data, | ||
| 103 | std::size_t size, | ||
| 104 | system::error_code& ec) | ||
| 105 | { | ||
| 106 | 2001533 | auto const n = write_some( | |
| 107 | data, size, ec); | ||
| 108 |
6/6✓ Branch 1 taken 2001509 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 2001501 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 2001524 times.
|
2001532 | if(! ec && n < size) |
| 109 | { | ||
| 110 | 8 | BOOST_JSON_FAIL(ec, error::extra_data); | |
| 111 | 8 | p_.fail(ec); | |
| 112 | } | ||
| 113 | 2001532 | return n; | |
| 114 | } | ||
| 115 | |||
| 116 | std::size_t | ||
| 117 | 7 | parser:: | |
| 118 | write( | ||
| 119 | char const* data, | ||
| 120 | std::size_t size, | ||
| 121 | std::error_code& ec) | ||
| 122 | { | ||
| 123 | 7 | system::error_code jec; | |
| 124 |
1/1✓ Branch 1 taken 7 times.
|
7 | std::size_t const result = write(data, size, jec); |
| 125 |
1/1✓ Branch 1 taken 7 times.
|
7 | ec = jec; |
| 126 | 7 | return result; | |
| 127 | } | ||
| 128 | |||
| 129 | std::size_t | ||
| 130 | 14 | parser:: | |
| 131 | write( | ||
| 132 | char const* data, | ||
| 133 | std::size_t size) | ||
| 134 | { | ||
| 135 | 14 | system::error_code ec; | |
| 136 |
1/1✓ Branch 1 taken 14 times.
|
14 | auto const n = write( |
| 137 | data, size, ec); | ||
| 138 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 6 times.
|
14 | if(ec) |
| 139 | 8 | detail::throw_system_error( ec ); | |
| 140 | 6 | return n; | |
| 141 | } | ||
| 142 | |||
| 143 | value | ||
| 144 | 2001495 | parser:: | |
| 145 | release() | ||
| 146 | { | ||
| 147 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2001491 times.
|
2001495 | if( ! p_.done()) |
| 148 | { | ||
| 149 | // prevent undefined behavior | ||
| 150 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
4 | if(! p_.last_error()) |
| 151 | { | ||
| 152 | 2 | system::error_code ec; | |
| 153 | 2 | BOOST_JSON_FAIL(ec, error::incomplete); | |
| 154 | 2 | p_.fail(ec); | |
| 155 | } | ||
| 156 | 8 | detail::throw_system_error( | |
| 157 | 8 | p_.last_error()); | |
| 158 | } | ||
| 159 | 2001491 | return p_.handler().st.release(); | |
| 160 | } | ||
| 161 | |||
| 162 | } // namespace json | ||
| 163 | } // namespace boost | ||
| 164 | |||
| 165 | #endif | ||
| 166 |