diff options
author | Alexander Zaitsev <zamazan4ik@tut.by> | 2020-03-13 03:56:35 +0300 |
---|---|---|
committer | Alexander Zaitsev <zamazan4ik@tut.by> | 2020-03-13 03:56:35 +0300 |
commit | 26fac5bf7e87dd5704a967ee4c744228b93d20b7 (patch) | |
tree | 74e5daa9a58f3a97b417925a212ac2cd31487a5e | |
parent | 806e7e5a3edf4fdf2b9c48469a7bc23307b200b0 (diff) |
fix: use std::size_t instead of size_t
- use C++ size_t from std namespace instead of a version from global namespace
Tested:
- Local build
- Unit-tests
-rw-r--r-- | include/tgbot/net/HttpServer.h | 9 | ||||
-rw-r--r-- | include/tgbot/tools/StringTools.h | 3 | ||||
-rw-r--r-- | src/EventHandler.cpp | 8 | ||||
-rw-r--r-- | src/net/BoostHttpOnlySslClient.cpp | 4 | ||||
-rw-r--r-- | src/net/CurlHttpClient.cpp | 4 | ||||
-rw-r--r-- | src/net/HttpParser.cpp | 11 | ||||
-rw-r--r-- | src/net/Url.cpp | 4 | ||||
-rw-r--r-- | src/tools/StringTools.cpp | 8 | ||||
-rw-r--r-- | test/utils.h | 2 |
9 files changed, 32 insertions, 21 deletions
diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h index 28ea5a3..ccee077 100644 --- a/include/tgbot/net/HttpServer.h +++ b/include/tgbot/net/HttpServer.h @@ -1,6 +1,7 @@ #ifndef TGBOT_HTTPSERVER_H #define TGBOT_HTTPSERVER_H +#include <cstddef> #include <iostream> #include <string> #include <utility> @@ -73,7 +74,7 @@ protected: _socket, *data, "\r\n\r\n", - [self, data](const boost::system::error_code& e, size_t n) { + [self, data](const boost::system::error_code& e, std::size_t n) { if (e) { std::cout << "error in HttpServer::Connection#_readHeader: " << e << std::endl; return; @@ -97,7 +98,7 @@ protected: boost::asio::async_write( self->_socket, boost::asio::buffer(answer), - [](const boost::system::error_code& e, size_t n) { }); + [](const boost::system::error_code& e, std::size_t n) { }); return; } @@ -114,7 +115,7 @@ protected: boost::asio::async_read(_socket, *data, boost::asio::transfer_exactly(size - data->size()), - [self, data, size, headers](const boost::system::error_code& e, size_t n) { + [self, data, size, headers](const boost::system::error_code& e, std::size_t n) { if (e) { std::cout << "error in HttpServer::Connection#_readBody: " << e << std::endl; return; @@ -133,7 +134,7 @@ protected: boost::asio::async_write( self->_socket, boost::asio::buffer(answer), - [](const boost::system::error_code& e, size_t n) { }); + [](const boost::system::error_code& e, std::size_t n) { }); self->_socket.close(); }); diff --git a/include/tgbot/tools/StringTools.h b/include/tgbot/tools/StringTools.h index d1bc094..cb26bb5 100644 --- a/include/tgbot/tools/StringTools.h +++ b/include/tgbot/tools/StringTools.h @@ -1,6 +1,7 @@ #ifndef TGBOT_CPP_STRINGTOOLS_H #define TGBOT_CPP_STRINGTOOLS_H +#include <cstddef> #include <vector> #include <string> #include <sstream> @@ -36,7 +37,7 @@ void split(const std::string& str, char delimiter, std::vector<std::string>& des * Generates pseudo random string. It's recommended to call srand before this method. * @param length Length of resulting string. */ -std::string generateRandomString(size_t length); +std::string generateRandomString(std::size_t length); /** * Performs url encode. diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 505704d..cd67379 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -1,5 +1,7 @@ #include "tgbot/EventHandler.h" + #include <algorithm> +#include <cstddef> using namespace std; @@ -24,9 +26,9 @@ void EventHandler::handleMessage(Message::Ptr message) const { _broadcaster.broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { - size_t splitPosition; - size_t spacePosition = message->text.find(' '); - size_t atSymbolPosition = message->text.find('@'); + std::size_t splitPosition; + std::size_t spacePosition = message->text.find(' '); + std::size_t atSymbolPosition = message->text.find('@'); if (spacePosition == string::npos) { if (atSymbolPosition == string::npos) { splitPosition = message->text.size(); diff --git a/src/net/BoostHttpOnlySslClient.cpp b/src/net/BoostHttpOnlySslClient.cpp index d0fde8e..836b06a 100644 --- a/src/net/BoostHttpOnlySslClient.cpp +++ b/src/net/BoostHttpOnlySslClient.cpp @@ -1,5 +1,7 @@ #include "tgbot/net/BoostHttpOnlySslClient.h" +#include <cstddef> + #include <boost/asio/ssl.hpp> using namespace std; @@ -59,7 +61,7 @@ string BoostHttpOnlySslClient::makeRequest(const Url& url, const vector<HttpReqA boost::system::error_code error; while (!error) { - size_t bytes = read(socket, buffer(buff), error); + std::size_t bytes = read(socket, buffer(buff), error); response += string(buff, bytes); } diff --git a/src/net/CurlHttpClient.cpp b/src/net/CurlHttpClient.cpp index 01115e6..5bd9313 100644 --- a/src/net/CurlHttpClient.cpp +++ b/src/net/CurlHttpClient.cpp @@ -2,6 +2,8 @@ #include "tgbot/net/CurlHttpClient.h" +#include <cstddef> + #include <boost/asio/ssl.hpp> namespace TgBot { @@ -14,7 +16,7 @@ CurlHttpClient::~CurlHttpClient() { curl_easy_cleanup(curlSettings); } -static size_t curlWriteString(char* ptr, size_t size, size_t nmemb, void* userdata) { +static std::size_t curlWriteString(char* ptr, std::size_t size, std::size_t nmemb, void* userdata) { static_cast<std::string *>(userdata)->append(ptr, size * nmemb); return size * nmemb; }; diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp index 386a4d9..8006c85 100644 --- a/src/net/HttpParser.cpp +++ b/src/net/HttpParser.cpp @@ -1,5 +1,6 @@ #include "tgbot/net/HttpParser.h" +#include <cstddef> #include <cstdint> #include <boost/algorithm/string.hpp> @@ -133,10 +134,10 @@ string HttpParser::generateResponse(const string& data, const string& mimeType, unordered_map<string, string> HttpParser::parseHeader(const string& data, bool isRequest) const { unordered_map<string, string> headers; - size_t lineStart = 0; - size_t lineEnd = 0; - size_t lineSepPos = 0; - size_t lastLineEnd = string::npos; + std::size_t lineStart = 0; + std::size_t lineEnd = 0; + std::size_t lineSepPos = 0; + std::size_t lastLineEnd = string::npos; while (lastLineEnd != lineEnd) { lastLineEnd = lineEnd; bool isFirstLine = lineEnd == 0; @@ -167,7 +168,7 @@ unordered_map<string, string> HttpParser::parseHeader(const string& data, bool i } string HttpParser::extractBody(const string& data) const { - size_t headerEnd = data.find("\r\n\r\n"); + std::size_t headerEnd = data.find("\r\n\r\n"); if (headerEnd == string::npos) { return data; } diff --git a/src/net/Url.cpp b/src/net/Url.cpp index c767b47..016a97f 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -1,5 +1,7 @@ #include "tgbot/net/Url.h" +#include <cstddef> + #include "tgbot/tools/StringTools.h" using namespace std; @@ -12,7 +14,7 @@ Url::Url(const string& url) { bool isPathParsed = false; bool isQueryParsed = false; - for (size_t i = 0, count = url.length(); i < count; ++i) { + for (std::size_t i = 0, count = url.length(); i < count; ++i) { char c = url[i]; if (!isProtocolParsed) { diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index 2d2e24c..1246c50 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -54,11 +54,11 @@ void split(const string& str, char delimiter, vector<string>& dest) { } } -string generateRandomString(size_t length) { +string generateRandomString(std::size_t length) { static const string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=[]\\;',./!@#$%^&*()_+{}|:\"<>?`~"); - static const size_t charsLen = chars.length(); + static const std::size_t charsLen = chars.length(); string result; - for (size_t i = 0; i < length; ++i) { + for (std::size_t i = 0; i < length; ++i) { result += chars[rand() % charsLen]; } return result; @@ -81,7 +81,7 @@ string urlEncode(const string& value, const std::string& additionalLegitChars) { string urlDecode(const string& value) { string result; - for (size_t i = 0, count = value.length(); i < count; ++i) { + for (std::size_t i = 0, count = value.length(); i < count; ++i) { const char c = value[i]; if (c == '%') { int t = 0; diff --git a/test/utils.h b/test/utils.h index e49534e..5951550 100644 --- a/test/utils.h +++ b/test/utils.h @@ -24,7 +24,7 @@ inline std::string diff(const T& test, const T& expected, std::string (*toString typename T::const_iterator end2 = expected.end(); bool r1, r2; std::string s1, s2; - size_t i = 0; + std::size_t i = 0; do { r1 = iter1 != end1; r2 = iter2 != end2; |