From aa8e7432c2d684029f49d9d7e23b6632957562da Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 9 Nov 2016 10:40:09 -0500 Subject: [PATCH] Use boost::lexical_cast instead of std::to_string fix #176 --- CHANGELOG.md | 1 + examples/http_crawl.cpp | 5 +++-- examples/http_example.cpp | 4 +++- examples/ssl/http_ssl_example.cpp | 3 ++- extras/beast/unit_test/reporter.hpp | 4 +++- extras/beast/unit_test/suite.hpp | 3 ++- include/beast/http/impl/message.ipp | 8 ++++---- test/http/basic_headers.cpp | 3 ++- test/websocket/websocket_async_echo_server.hpp | 3 ++- test/websocket/websocket_sync_echo_server.hpp | 3 ++- 10 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5e8d2c..6ad7ae6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Boost library min/max guidance * Improvements to code coverage +* Use boost::lexical_cast instead of std::to_string HTTP diff --git a/examples/http_crawl.cpp b/examples/http_crawl.cpp index 262efbbd..b968abbb 100644 --- a/examples/http_crawl.cpp +++ b/examples/http_crawl.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include using namespace beast::http; @@ -39,8 +40,8 @@ int main(int, char const*[]) req.method = "GET"; req.url = "/"; req.version = 11; - req.headers.insert("Host", host + - std::string(":") + std::to_string(ep.port())); + req.headers.insert("Host", host + std::string(":") + + boost::lexical_cast(ep.port())); req.headers.insert("User-Agent", "beast/http"); prepare(req); write(sock, req); diff --git a/examples/http_example.cpp b/examples/http_example.cpp index 10a246d4..2ccbc3be 100644 --- a/examples/http_example.cpp +++ b/examples/http_example.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -25,7 +26,8 @@ int main() req.method = "GET"; req.url = "/"; req.version = 11; - req.headers.replace("Host", host + ":" + std::to_string(sock.remote_endpoint().port())); + req.headers.replace("Host", host + ":" + + boost::lexical_cast(sock.remote_endpoint().port())); req.headers.replace("User-Agent", "Beast"); beast::http::prepare(req); beast::http::write(sock, req); diff --git a/examples/ssl/http_ssl_example.cpp b/examples/ssl/http_ssl_example.cpp index bec4d6d6..09e921cf 100644 --- a/examples/ssl/http_ssl_example.cpp +++ b/examples/ssl/http_ssl_example.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -38,7 +39,7 @@ int main() req.url = "/"; req.version = 11; req.headers.insert("Host", host + ":" + - std::to_string(sock.remote_endpoint().port())); + boost::lexical_cast(sock.remote_endpoint().port())); req.headers.insert("User-Agent", "Beast"); beast::http::prepare(req); beast::http::write(stream, req); diff --git a/extras/beast/unit_test/reporter.hpp b/extras/beast/unit_test/reporter.hpp index 9b771cd6..c521fc23 100644 --- a/extras/beast/unit_test/reporter.hpp +++ b/extras/beast/unit_test/reporter.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -214,7 +215,8 @@ reporter<_>::fmtdur(typename clock_type::duration const& d) using namespace std::chrono; auto const ms = duration_cast(d); if(ms < seconds{1}) - return std::to_string(ms.count()) + "ms"; + return boost::lexical_cast( + ms.count()) + "ms"; std::stringstream ss; ss << std::fixed << std::setprecision(1) << (ms.count()/1000.) << "s"; diff --git a/extras/beast/unit_test/suite.hpp b/extras/beast/unit_test/suite.hpp index 54aab4ad..cf01ee0e 100644 --- a/extras/beast/unit_test/suite.hpp +++ b/extras/beast/unit_test/suite.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -31,7 +32,7 @@ make_reason(String const& reason, namespace fs = boost::filesystem; s.append(fs::path{file}.filename().string()); s.append("("); - s.append(std::to_string(line)); + s.append(boost::lexical_cast(line)); s.append(")"); return s; } diff --git a/include/beast/http/impl/message.ipp b/include/beast/http/impl/message.ipp index 7c29bf48..ea6c26f5 100644 --- a/include/beast/http/impl/message.ipp +++ b/include/beast/http/impl/message.ipp @@ -199,8 +199,8 @@ prepare(message& msg, if(*pi.content_length > 0 || ci_equal(msg.method, "POST")) { - msg.headers.insert("Content-Length", - std::to_string(*pi.content_length)); + msg.headers.insert( + "Content-Length", *pi.content_length); } } @@ -212,8 +212,8 @@ prepare(message& msg, msg.status != 204 && msg.status != 304) { - msg.headers.insert("Content-Length", - std::to_string(*pi.content_length)); + msg.headers.insert( + "Content-Length", *pi.content_length); } } }; diff --git a/test/http/basic_headers.cpp b/test/http/basic_headers.cpp index cc01d7d3..25b55a59 100644 --- a/test/http/basic_headers.cpp +++ b/test/http/basic_headers.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace beast { namespace http { @@ -27,7 +28,7 @@ public: fill(std::size_t n, basic_headers& h) { for(std::size_t i = 1; i<= n; ++i) - h.insert(std::to_string(i), i); + h.insert(boost::lexical_cast(i), i); } template diff --git a/test/websocket/websocket_async_echo_server.hpp b/test/websocket/websocket_async_echo_server.hpp index 35201f00..21b56e6b 100644 --- a/test/websocket/websocket_async_echo_server.hpp +++ b/test/websocket/websocket_async_echo_server.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -277,7 +278,7 @@ private: d.state = 1; d.ws.async_handshake( d.ep->address().to_string() + ":" + - std::to_string(d.ep->port()), + boost::lexical_cast(d.ep->port()), "/", d.strand.wrap(std::move(*this))); return; } diff --git a/test/websocket/websocket_sync_echo_server.hpp b/test/websocket/websocket_sync_echo_server.hpp index ca7a8486..fd3dba2d 100644 --- a/test/websocket/websocket_sync_echo_server.hpp +++ b/test/websocket/websocket_sync_echo_server.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -84,7 +85,7 @@ private: fail(int id, error_code ec, std::string what) { if(log_) - std::cerr << "#" << std::to_string(id) << " " << + std::cerr << "#" << boost::lexical_cast(id) << " " << what << ": " << ec.message() << std::endl; }