96.08% Lines (49/51)
100.00% Functions (6/6)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | 3 | // Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com) | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/boostorg/json | 8 | // Official repository: https://github.com/boostorg/json | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_JSON_IMPL_PARSE_IPP | 11 | #ifndef BOOST_JSON_IMPL_PARSE_IPP | |||||
| 12 | #define BOOST_JSON_IMPL_PARSE_IPP | 12 | #define BOOST_JSON_IMPL_PARSE_IPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/json/parse.hpp> | 14 | #include <boost/json/parse.hpp> | |||||
| 15 | #include <boost/json/parser.hpp> | 15 | #include <boost/json/parser.hpp> | |||||
| 16 | #include <boost/json/detail/except.hpp> | 16 | #include <boost/json/detail/except.hpp> | |||||
| 17 | 17 | |||||||
| 18 | #include <istream> | 18 | #include <istream> | |||||
| 19 | 19 | |||||||
| 20 | namespace boost { | 20 | namespace boost { | |||||
| 21 | namespace json { | 21 | namespace json { | |||||
| 22 | 22 | |||||||
| 23 | value | 23 | value | |||||
| HITCBC | 24 | 2001505 | parse( | 24 | 2001505 | parse( | ||
| 25 | string_view s, | 25 | string_view s, | |||||
| 26 | system::error_code& ec, | 26 | system::error_code& ec, | |||||
| 27 | storage_ptr sp, | 27 | storage_ptr sp, | |||||
| 28 | const parse_options& opt) | 28 | const parse_options& opt) | |||||
| 29 | { | 29 | { | |||||
| 30 | unsigned char temp[ | 30 | unsigned char temp[ | |||||
| 31 | BOOST_JSON_STACK_BUFFER_SIZE]; | 31 | BOOST_JSON_STACK_BUFFER_SIZE]; | |||||
| HITCBC | 32 | 2001505 | parser p(storage_ptr(), opt, temp); | 32 | 2001505 | parser p(storage_ptr(), opt, temp); | ||
| HITCBC | 33 | 2001505 | p.reset(std::move(sp)); | 33 | 2001505 | p.reset(std::move(sp)); | ||
| HITCBC | 34 | 2001505 | p.write(s, ec); | 34 | 2001505 | p.write(s, ec); | ||
| HITCBC | 35 | 2001504 | if(ec) | 35 | 2001504 | if(ec) | ||
| HITCBC | 36 | 15 | return nullptr; | 36 | 15 | return nullptr; | ||
| HITCBC | 37 | 2001489 | return p.release(); | 37 | 2001489 | return p.release(); | ||
| HITCBC | 38 | 2001505 | } | 38 | 2001505 | } | ||
| 39 | 39 | |||||||
| 40 | value | 40 | value | |||||
| HITCBC | 41 | 4 | parse( | 41 | 4 | parse( | ||
| 42 | string_view s, | 42 | string_view s, | |||||
| 43 | std::error_code& ec, | 43 | std::error_code& ec, | |||||
| 44 | storage_ptr sp, | 44 | storage_ptr sp, | |||||
| 45 | parse_options const& opt) | 45 | parse_options const& opt) | |||||
| 46 | { | 46 | { | |||||
| HITCBC | 47 | 4 | system::error_code jec; | 47 | 4 | system::error_code jec; | ||
| HITCBC | 48 | 4 | value result = parse(s, jec, std::move(sp), opt); | 48 | 4 | value result = parse(s, jec, std::move(sp), opt); | ||
| HITCBC | 49 | 4 | ec = jec; | 49 | 4 | ec = jec; | ||
| HITCBC | 50 | 8 | return result; | 50 | 8 | return result; | ||
| MISUBC | 51 | ✗ | } | 51 | ✗ | } | ||
| 52 | 52 | |||||||
| 53 | value | 53 | value | |||||
| HITCBC | 54 | 2001038 | parse( | 54 | 2001038 | parse( | ||
| 55 | string_view s, | 55 | string_view s, | |||||
| 56 | storage_ptr sp, | 56 | storage_ptr sp, | |||||
| 57 | const parse_options& opt) | 57 | const parse_options& opt) | |||||
| 58 | { | 58 | { | |||||
| HITCBC | 59 | 2001038 | system::error_code ec; | 59 | 2001038 | system::error_code ec; | ||
| 60 | auto jv = parse( | 60 | auto jv = parse( | |||||
| HITCBC | 61 | 2001039 | s, ec, std::move(sp), opt); | 61 | 2001039 | s, ec, std::move(sp), opt); | ||
| HITCBC | 62 | 2001037 | if(ec) | 62 | 2001037 | if(ec) | ||
| HITCBC | 63 | 2 | detail::throw_system_error( ec ); | 63 | 2 | detail::throw_system_error( ec ); | ||
| HITCBC | 64 | 4002070 | return jv; | 64 | 4002070 | return jv; | ||
| HITCBC | 65 | 2 | } | 65 | 2 | } | ||
| 66 | 66 | |||||||
| 67 | value | 67 | value | |||||
| HITCBC | 68 | 10 | parse( | 68 | 10 | parse( | ||
| 69 | std::istream& is, | 69 | std::istream& is, | |||||
| 70 | system::error_code& ec, | 70 | system::error_code& ec, | |||||
| 71 | storage_ptr sp, | 71 | storage_ptr sp, | |||||
| 72 | parse_options const& opt) | 72 | parse_options const& opt) | |||||
| 73 | { | 73 | { | |||||
| 74 | unsigned char parser_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2]; | 74 | unsigned char parser_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2]; | |||||
| HITCBC | 75 | 10 | stream_parser p(storage_ptr(), opt, parser_buffer); | 75 | 10 | stream_parser p(storage_ptr(), opt, parser_buffer); | ||
| HITCBC | 76 | 10 | p.reset(std::move(sp)); | 76 | 10 | p.reset(std::move(sp)); | ||
| 77 | 77 | |||||||
| 78 | char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2]; | 78 | char read_buffer[BOOST_JSON_STACK_BUFFER_SIZE / 2]; | |||||
| 79 | do | 79 | do | |||||
| 80 | { | 80 | { | |||||
| HITCBC | 81 | 17 | if( is.eof() ) | 81 | 17 | if( is.eof() ) | ||
| 82 | { | 82 | { | |||||
| HITCBC | 83 | 7 | p.finish(ec); | 83 | 7 | p.finish(ec); | ||
| HITCBC | 84 | 7 | break; | 84 | 7 | break; | ||
| 85 | } | 85 | } | |||||
| 86 | 86 | |||||||
| HITCBC | 87 | 10 | if( !is ) | 87 | 10 | if( !is ) | ||
| 88 | { | 88 | { | |||||
| HITCBC | 89 | 1 | BOOST_JSON_FAIL( ec, error::input_error ); | 89 | 1 | BOOST_JSON_FAIL( ec, error::input_error ); | ||
| HITCBC | 90 | 1 | break; | 90 | 1 | break; | ||
| 91 | } | 91 | } | |||||
| 92 | 92 | |||||||
| HITCBC | 93 | 9 | is.read(read_buffer, sizeof(read_buffer)); | 93 | 9 | is.read(read_buffer, sizeof(read_buffer)); | ||
| HITCBC | 94 | 9 | auto const consumed = is.gcount(); | 94 | 9 | auto const consumed = is.gcount(); | ||
| 95 | 95 | |||||||
| HITCBC | 96 | 9 | p.write( read_buffer, static_cast<std::size_t>(consumed), ec ); | 96 | 9 | p.write( read_buffer, static_cast<std::size_t>(consumed), ec ); | ||
| 97 | } | 97 | } | |||||
| HITCBC | 98 | 9 | while( !ec.failed() ); | 98 | 9 | while( !ec.failed() ); | ||
| 99 | 99 | |||||||
| HITCBC | 100 | 10 | if( ec.failed() ) | 100 | 10 | if( ec.failed() ) | ||
| HITCBC | 101 | 3 | return nullptr; | 101 | 3 | return nullptr; | ||
| 102 | 102 | |||||||
| HITCBC | 103 | 7 | return p.release(); | 103 | 7 | return p.release(); | ||
| HITCBC | 104 | 10 | } | 104 | 10 | } | ||
| 105 | 105 | |||||||
| 106 | value | 106 | value | |||||
| HITCBC | 107 | 4 | parse( | 107 | 4 | parse( | ||
| 108 | std::istream& is, | 108 | std::istream& is, | |||||
| 109 | std::error_code& ec, | 109 | std::error_code& ec, | |||||
| 110 | storage_ptr sp, | 110 | storage_ptr sp, | |||||
| 111 | parse_options const& opt) | 111 | parse_options const& opt) | |||||
| 112 | { | 112 | { | |||||
| HITCBC | 113 | 4 | system::error_code jec; | 113 | 4 | system::error_code jec; | ||
| HITCBC | 114 | 4 | value result = parse(is, jec, std::move(sp), opt); | 114 | 4 | value result = parse(is, jec, std::move(sp), opt); | ||
| HITCBC | 115 | 4 | ec = jec; | 115 | 4 | ec = jec; | ||
| HITCBC | 116 | 8 | return result; | 116 | 8 | return result; | ||
| MISUBC | 117 | ✗ | } | 117 | ✗ | } | ||
| 118 | 118 | |||||||
| 119 | value | 119 | value | |||||
| HITCBC | 120 | 2 | parse( | 120 | 2 | parse( | ||
| 121 | std::istream& is, | 121 | std::istream& is, | |||||
| 122 | storage_ptr sp, | 122 | storage_ptr sp, | |||||
| 123 | parse_options const& opt) | 123 | parse_options const& opt) | |||||
| 124 | { | 124 | { | |||||
| HITCBC | 125 | 2 | system::error_code ec; | 125 | 2 | system::error_code ec; | ||
| 126 | auto jv = parse( | 126 | auto jv = parse( | |||||
| HITCBC | 127 | 2 | is, ec, std::move(sp), opt); | 127 | 2 | is, ec, std::move(sp), opt); | ||
| HITCBC | 128 | 2 | if(ec) | 128 | 2 | if(ec) | ||
| HITCBC | 129 | 1 | detail::throw_system_error( ec ); | 129 | 1 | detail::throw_system_error( ec ); | ||
| HITCBC | 130 | 2 | return jv; | 130 | 2 | return jv; | ||
| HITCBC | 131 | 1 | } | 131 | 1 | } | ||
| 132 | 132 | |||||||
| 133 | } // namespace json | 133 | } // namespace json | |||||
| 134 | } // namespace boost | 134 | } // namespace boost | |||||
| 135 | 135 | |||||||
| 136 | #endif | 136 | #endif | |||||