mirror of
https://github.com/boostorg/json.git
synced 2026-02-12 00:02:14 +00:00
Eliminate dependencies
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
#include <boost/json/number.hpp>
|
||||
#include <boost/json/detail/basic_parser.hpp>
|
||||
#include <boost/json/detail/stack.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -71,44 +70,18 @@ public:
|
||||
void
|
||||
reset();
|
||||
|
||||
template<
|
||||
class ConstBufferSequence
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
,class = typename std::enable_if<
|
||||
! std::is_convertible<
|
||||
ConstBufferSequence,
|
||||
boost::asio::const_buffer>::value>::type
|
||||
#endif
|
||||
>
|
||||
std::size_t
|
||||
write_some(
|
||||
ConstBufferSequence const& buffers,
|
||||
error_code& ec);
|
||||
|
||||
BOOST_JSON_DECL
|
||||
std::size_t
|
||||
write_some(
|
||||
boost::asio::const_buffer buffer,
|
||||
error_code& ec);
|
||||
|
||||
template<
|
||||
class ConstBufferSequence
|
||||
#ifndef GENERATING_DOCUMENTATION
|
||||
,class = typename std::enable_if<
|
||||
! std::is_convertible<
|
||||
ConstBufferSequence,
|
||||
boost::asio::const_buffer>::value>::type
|
||||
#endif
|
||||
>
|
||||
std::size_t
|
||||
write(
|
||||
ConstBufferSequence const& buffers,
|
||||
void const* data,
|
||||
std::size_t size,
|
||||
error_code& ec);
|
||||
|
||||
BOOST_JSON_DECL
|
||||
std::size_t
|
||||
write(
|
||||
boost::asio::const_buffer buffer,
|
||||
void const* data,
|
||||
std::size_t size,
|
||||
error_code& ec);
|
||||
|
||||
BOOST_JSON_DECL
|
||||
@@ -192,7 +165,6 @@ protected:
|
||||
} // json
|
||||
} // boost
|
||||
|
||||
#include <boost/json/impl/basic_parser.hpp>
|
||||
#ifdef BOOST_JSON_HEADER_ONLY
|
||||
#include <boost/json/impl/basic_parser.ipp>
|
||||
#endif
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/vinniefalco/json
|
||||
//
|
||||
|
||||
#ifndef BOOST_JSON_IMPL_BASIC_PARSER_HPP
|
||||
#define BOOST_JSON_IMPL_BASIC_PARSER_HPP
|
||||
|
||||
namespace boost {
|
||||
namespace json {
|
||||
|
||||
template<class ConstBufferSequence, class>
|
||||
std::size_t
|
||||
basic_parser::
|
||||
write_some(
|
||||
ConstBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence type requirements not met");
|
||||
|
||||
ec = {};
|
||||
std::size_t bytes_used = 0;
|
||||
auto it =
|
||||
boost::asio::buffer_sequence_begin(buffers);
|
||||
auto end =
|
||||
boost::asio::buffer_sequence_end(buffers);
|
||||
for(;it != end; ++it)
|
||||
{
|
||||
bytes_used +=
|
||||
write_some(*it, ec);
|
||||
if(ec)
|
||||
return bytes_used;
|
||||
}
|
||||
return bytes_used;
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence, class>
|
||||
std::size_t
|
||||
basic_parser::
|
||||
write(
|
||||
ConstBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence type requirements not met");
|
||||
|
||||
ec = {};
|
||||
std::size_t bytes_used = 0;
|
||||
auto it =
|
||||
boost::asio::buffer_sequence_begin(buffers);
|
||||
auto end =
|
||||
boost::asio::buffer_sequence_end(buffers);
|
||||
if(it != end)
|
||||
{
|
||||
for(--end; it != end; ++it)
|
||||
{
|
||||
bytes_used +=
|
||||
write_some(*it, ec);
|
||||
if(ec)
|
||||
return bytes_used;
|
||||
}
|
||||
bytes_used += write(*it, ec);
|
||||
}
|
||||
return bytes_used;
|
||||
}
|
||||
|
||||
} // json
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/json/basic_parser.hpp>
|
||||
#include <boost/json/error.hpp>
|
||||
#include <boost/beast/core/static_string.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
@@ -164,9 +163,7 @@ write_eof(error_code& ec)
|
||||
[this, &ec]
|
||||
{
|
||||
char c = 0;
|
||||
write_some(
|
||||
boost::asio::const_buffer(
|
||||
&c, 1), ec);
|
||||
write_some(&c, 1, ec);
|
||||
BOOST_ASSERT(ec);
|
||||
};
|
||||
|
||||
@@ -182,8 +179,7 @@ write_eof(error_code& ec)
|
||||
case state::number_exp:
|
||||
case state::number_exp_digits2:
|
||||
stack_.front() = state::number_end;
|
||||
write_some(
|
||||
boost::asio::const_buffer{}, ec);
|
||||
write_some(nullptr, 0, ec);
|
||||
if(ec)
|
||||
return;
|
||||
break;
|
||||
@@ -204,15 +200,16 @@ write_eof(error_code& ec)
|
||||
std::size_t
|
||||
basic_parser::
|
||||
write_some(
|
||||
boost::asio::const_buffer buffer,
|
||||
void const* data,
|
||||
std::size_t size,
|
||||
error_code& ec)
|
||||
{
|
||||
auto p = static_cast<
|
||||
char const*>(buffer.data());
|
||||
auto n = buffer.size();
|
||||
auto p = static_cast<char const*>(data);
|
||||
auto n = size;
|
||||
auto const p0 = p;
|
||||
auto const p1 = p0 + n;
|
||||
beast::static_string<4096> temp;
|
||||
std::string temp; // VFALCO string bad!
|
||||
temp.reserve(4096);
|
||||
ec = {};
|
||||
BOOST_ASSERT(stack_.front() != state::end);
|
||||
auto const maybe_flush =
|
||||
@@ -1015,11 +1012,12 @@ finish:
|
||||
std::size_t
|
||||
basic_parser::
|
||||
write(
|
||||
boost::asio::const_buffer buffer,
|
||||
void const* data,
|
||||
std::size_t size,
|
||||
error_code& ec)
|
||||
{
|
||||
auto bytes_used =
|
||||
write_some(buffer, ec);
|
||||
write_some(data, size, ec);
|
||||
if(! ec)
|
||||
write_eof(ec);
|
||||
return bytes_used;
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
const char*
|
||||
name() const noexcept override
|
||||
{
|
||||
return "boost.beast.json";
|
||||
return "boost.json";
|
||||
}
|
||||
|
||||
BOOST_JSON_DECL
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
const char*
|
||||
name() const noexcept override
|
||||
{
|
||||
return "boost.beast";
|
||||
return "boost.json";
|
||||
}
|
||||
|
||||
BOOST_JSON_DECL
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
#ifndef BOOST_JSON_IMPL_PARSE_FILE_IPP
|
||||
#define BOOST_JSON_IMPL_PARSE_FILE_IPP
|
||||
|
||||
#include <boost/beast/core/file.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/detail/clamp.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
namespace boost {
|
||||
namespace json {
|
||||
@@ -23,34 +22,47 @@ parse_file(
|
||||
basic_parser& parser,
|
||||
error_code& ec)
|
||||
{
|
||||
beast::file f;
|
||||
f.open(path, beast::file_mode::scan, ec);
|
||||
if(ec)
|
||||
return;
|
||||
beast::flat_buffer b;
|
||||
auto remain = f.size(ec);
|
||||
if(ec)
|
||||
return;
|
||||
while(remain > 0)
|
||||
auto const& gc =
|
||||
boost::system::generic_category();
|
||||
|
||||
struct cleanup
|
||||
{
|
||||
auto amount = beast::detail::clamp(remain);
|
||||
auto mb = b.prepare(amount);
|
||||
b.commit(f.read(mb.data(), mb.size(), ec));
|
||||
if(ec)
|
||||
return;
|
||||
if(remain == b.size())
|
||||
break;
|
||||
auto bytes_used =
|
||||
parser.write_some(b.data(), ec);
|
||||
if(ec)
|
||||
return;
|
||||
remain -= b.size();
|
||||
b.consume(bytes_used);
|
||||
}
|
||||
parser.write(b.data(), ec);
|
||||
if(ec)
|
||||
FILE* f;
|
||||
~cleanup()
|
||||
{
|
||||
::fclose(f);
|
||||
}
|
||||
};
|
||||
|
||||
auto f = ::fopen(path, "rb");
|
||||
if(! f)
|
||||
{
|
||||
ec = error_code(errno, gc);
|
||||
return;
|
||||
// finished
|
||||
}
|
||||
cleanup c{f};
|
||||
std::size_t result;
|
||||
result = ::fseek(f, 0, SEEK_END);
|
||||
if(result != 0)
|
||||
{
|
||||
ec = error_code(errno, gc);
|
||||
return;
|
||||
}
|
||||
auto const size = ::ftell(f);
|
||||
if(size == -1L)
|
||||
{
|
||||
ec = error_code(errno, gc);
|
||||
return;
|
||||
}
|
||||
char* buf = new char[size];
|
||||
result = ::fread(buf, 1, size, f);
|
||||
if(result != 0)
|
||||
{
|
||||
ec = error_code(errno, gc);
|
||||
return;
|
||||
}
|
||||
parser.write(buf, size, ec);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
} // json
|
||||
|
||||
Reference in New Issue
Block a user