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