mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 04:47:29 +02:00
Remove use of lexical_cast
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
Version 86:
|
||||
|
||||
* Boost prep
|
||||
* Remove use of lexical_cast
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/beast/unit_test/amount.hpp>
|
||||
#include <boost/beast/unit_test/recorder.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
@ -218,8 +217,7 @@ reporter<_>::fmtdur(typename clock_type::duration const& d)
|
||||
using namespace std::chrono;
|
||||
auto const ms = duration_cast<milliseconds>(d);
|
||||
if(ms < seconds{1})
|
||||
return boost::lexical_cast<std::string>(
|
||||
ms.count()) + "ms";
|
||||
return std::to_string(ms.count()) + "ms";
|
||||
std::stringstream ss;
|
||||
ss << std::fixed << std::setprecision(1) <<
|
||||
(ms.count()/1000.) << "s";
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/beast/unit_test/runner.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
@ -36,7 +35,7 @@ make_reason(String const& reason,
|
||||
namespace fs = boost::filesystem;
|
||||
s.append(fs::path{file}.filename().string());
|
||||
s.append("(");
|
||||
s.append(boost::lexical_cast<std::string>(line));
|
||||
s.append(std::to_string(line));
|
||||
s.append(")");
|
||||
return s;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
@ -42,8 +41,14 @@ public:
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
return boost::lexical_cast<
|
||||
std::string>(buffers(bs));
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
corpus
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
@ -30,8 +29,14 @@ public:
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
return boost::lexical_cast<
|
||||
std::string>(buffers(bs));
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
void testBuffersAdapter()
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/test/test_allocator.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost {
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace boost {
|
||||
@ -21,6 +20,21 @@ namespace beast {
|
||||
class ostream_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@ -29,8 +43,7 @@ public:
|
||||
auto os = ostream(b);
|
||||
os << "Hello, world!\n";
|
||||
os.flush();
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<std::string>(
|
||||
buffers(b.data())) == "Hello, world!\n");
|
||||
BOOST_BEAST_EXPECT(to_string(b.data()) == "Hello, world!\n");
|
||||
auto os2 = std::move(os);
|
||||
}
|
||||
{
|
||||
@ -45,8 +58,7 @@ public:
|
||||
"0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef";
|
||||
multi_buffer b;
|
||||
ostream(b) << s;
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<std::string>(
|
||||
buffers(b.data())) == s);
|
||||
BOOST_BEAST_EXPECT(to_string(b.data()) == s);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace boost {
|
||||
@ -43,6 +44,31 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
static
|
||||
std::string
|
||||
to_string(message<isRequest, Body, Fields> const& m)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << m;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
template<bool isRequest>
|
||||
bool
|
||||
equal_body(string_view sv, string_view body)
|
||||
@ -157,8 +183,7 @@ public:
|
||||
response<string_body> res;
|
||||
read_istream(is, buffer, res, ec);
|
||||
BOOST_BEAST_EXPECTS(! ec, ec.message());
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<
|
||||
std::string>(res) == s);
|
||||
BOOST_BEAST_EXPECT(to_string(res) == s);
|
||||
}
|
||||
|
||||
void
|
||||
@ -173,8 +198,7 @@ public:
|
||||
error_code ec;
|
||||
write_ostream(os, req, ec);
|
||||
BOOST_BEAST_EXPECTS(! ec, ec.message());
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<
|
||||
std::string>(req) == os.str());
|
||||
BOOST_BEAST_EXPECT(to_string(req) == os.str());
|
||||
}
|
||||
|
||||
void
|
||||
@ -343,8 +367,7 @@ public:
|
||||
std::allocator<double>{}
|
||||
), ec);
|
||||
BOOST_BEAST_EXPECT(
|
||||
boost::lexical_cast<std::string>(
|
||||
buffers(p.server.buffer.data())) ==
|
||||
to_string(p.server.buffer.data()) ==
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Server: test\r\n"
|
||||
"Accept: Expires, Content-MD5\r\n"
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <boost/beast/http/write.hpp>
|
||||
#include <boost/beast/test/string_istream.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
@ -28,6 +27,31 @@ class dynamic_body_test : public beast::unit_test::suite
|
||||
boost::asio::io_service ios_;
|
||||
|
||||
public:
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
static
|
||||
std::string
|
||||
to_string(message<isRequest, Body, Fields> const& m)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << m;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@ -42,9 +66,8 @@ public:
|
||||
multi_buffer b;
|
||||
read(ss, b, p);
|
||||
auto const& m = p.get();
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<std::string>(
|
||||
buffers(m.body.data())) == "xyz");
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<std::string>(m) == s);
|
||||
BOOST_BEAST_EXPECT(to_string(m.body.data()) == "xyz");
|
||||
BOOST_BEAST_EXPECT(to_string(m) == s);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <boost/beast/http/type_traits.hpp>
|
||||
#include <boost/beast/test/test_allocator.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
@ -37,7 +37,7 @@ public:
|
||||
fill(std::size_t n, basic_fields<Allocator>& f)
|
||||
{
|
||||
for(std::size_t i = 1; i<= n; ++i)
|
||||
f.insert(boost::lexical_cast<std::string>(i), i);
|
||||
f.insert(std::to_string(i), i);
|
||||
}
|
||||
|
||||
template<class U, class V>
|
||||
|
@ -258,6 +258,31 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
static
|
||||
std::string
|
||||
to_string(message<isRequest, Body, Fields> const& m)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << m;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
template<bool isRequest>
|
||||
bool
|
||||
equal_body(string_view sv, string_view body)
|
||||
@ -574,7 +599,7 @@ public:
|
||||
m.version = 11;
|
||||
m.set(field::user_agent, "test");
|
||||
m.body = "*";
|
||||
BOOST_BEAST_EXPECT(boost::lexical_cast<std::string>(m) ==
|
||||
BOOST_BEAST_EXPECT(to_string(m) ==
|
||||
"GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*");
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,17 @@ public:
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
return boost::lexical_cast<
|
||||
std::string>(buffers(bs));
|
||||
using boost::asio::buffer_cast;
|
||||
using boost::asio::buffer_size;
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(boost::asio::const_buffer b : bs)
|
||||
s.append(buffer_cast<char const*>(b),
|
||||
buffer_size(b));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
struct con
|
||||
{
|
||||
stream<socket_type> ws;
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
@ -374,8 +373,8 @@ private:
|
||||
if(d.server.log_)
|
||||
if(ec != boost::beast::websocket::error::closed)
|
||||
d.server.fail("[#" + std::to_string(d.id) +
|
||||
" " + boost::lexical_cast<std::string>(d.ep) +
|
||||
"] " + what, ec);
|
||||
" " + d.ep.address().to_string() + ":" +
|
||||
std::to_string(d.ep.port()) + "] " + what, ec);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
@ -216,8 +215,8 @@ private:
|
||||
if(log_)
|
||||
if(ec != boost::beast::websocket::error::closed)
|
||||
fail("[#" + std::to_string(id) + " " +
|
||||
boost::lexical_cast<std::string>(ep) +
|
||||
"] " + what, ec);
|
||||
ep.address().to_string() + ":" +
|
||||
std::to_string(ep.port()) + "] " + what, ec);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/beast/unit_test/dstream.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
@ -148,7 +147,7 @@ private:
|
||||
if(ec)
|
||||
return fail("on_connect", ec);
|
||||
ws_.async_handshake(
|
||||
boost::lexical_cast<std::string>(ep_),
|
||||
ep_.address().to_string() + ":" + std::to_string(ep_.port()),
|
||||
"/",
|
||||
alloc_.wrap(std::bind(
|
||||
&connection::on_handshake,
|
||||
|
Reference in New Issue
Block a user