File indexing completed on 2025-01-18 09:39:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_IMPL_PARSER_IPP
0011 #define BOOST_JSON_IMPL_PARSER_IPP
0012
0013 #include <boost/json/parser.hpp>
0014 #include <boost/json/basic_parser_impl.hpp>
0015 #include <boost/json/error.hpp>
0016 #include <cstring>
0017 #include <stdexcept>
0018 #include <utility>
0019
0020 namespace boost {
0021 namespace json {
0022
0023 parser::
0024 parser(
0025 storage_ptr sp,
0026 parse_options const& opt,
0027 unsigned char* buffer,
0028 std::size_t size) noexcept
0029 : p_(
0030 opt,
0031 std::move(sp),
0032 buffer,
0033 size)
0034 {
0035 reset();
0036 }
0037
0038 parser::
0039 parser(
0040 storage_ptr sp,
0041 parse_options const& opt) noexcept
0042 : p_(
0043 opt,
0044 std::move(sp),
0045 nullptr,
0046 0)
0047 {
0048 reset();
0049 }
0050
0051 void
0052 parser::
0053 reset(storage_ptr sp) noexcept
0054 {
0055 p_.reset();
0056 p_.handler().st.reset(sp);
0057 }
0058
0059 std::size_t
0060 parser::
0061 write_some(
0062 char const* data,
0063 std::size_t size,
0064 error_code& ec)
0065 {
0066 auto const n = p_.write_some(
0067 false, data, size, ec);
0068 BOOST_ASSERT(ec || p_.done());
0069 return n;
0070 }
0071
0072 std::size_t
0073 parser::
0074 write_some(
0075 char const* data,
0076 std::size_t size,
0077 std::error_code& ec)
0078 {
0079 error_code jec;
0080 std::size_t const result = write_some(data, size, jec);
0081 ec = jec;
0082 return result;
0083 }
0084
0085 std::size_t
0086 parser::
0087 write_some(
0088 char const* data,
0089 std::size_t size)
0090 {
0091 error_code ec;
0092 auto const n = write_some(
0093 data, size, ec);
0094 if(ec)
0095 detail::throw_system_error( ec );
0096 return n;
0097 }
0098
0099 std::size_t
0100 parser::
0101 write(
0102 char const* data,
0103 std::size_t size,
0104 error_code& ec)
0105 {
0106 auto const n = write_some(
0107 data, size, ec);
0108 if(! ec && n < size)
0109 {
0110 BOOST_JSON_FAIL(ec, error::extra_data);
0111 p_.fail(ec);
0112 }
0113 return n;
0114 }
0115
0116 std::size_t
0117 parser::
0118 write(
0119 char const* data,
0120 std::size_t size,
0121 std::error_code& ec)
0122 {
0123 error_code jec;
0124 std::size_t const result = write(data, size, jec);
0125 ec = jec;
0126 return result;
0127 }
0128
0129 std::size_t
0130 parser::
0131 write(
0132 char const* data,
0133 std::size_t size)
0134 {
0135 error_code ec;
0136 auto const n = write(
0137 data, size, ec);
0138 if(ec)
0139 detail::throw_system_error( ec );
0140 return n;
0141 }
0142
0143 value
0144 parser::
0145 release()
0146 {
0147 if( ! p_.done())
0148 {
0149
0150 if(! p_.last_error())
0151 {
0152 error_code ec;
0153 BOOST_JSON_FAIL(ec, error::incomplete);
0154 p_.fail(ec);
0155 }
0156 detail::throw_system_error(
0157 p_.last_error());
0158 }
0159 return p_.handler().st.release();
0160 }
0161
0162 }
0163 }
0164
0165 #endif