diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-05-11 22:29:51 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2017-05-11 22:29:51 +0200 |
commit | 3a418a0bbc8e155e5395595c5e25c038d3c7c773 (patch) | |
tree | 45359566bd6e360dd133e7ef43bc2a42e26baf56 /src/common/Utilities/Util.cpp | |
parent | 8abc56c540b5d2c583e40ad3d302c43068778ed1 (diff) |
Core/Common: Include cleanup
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index ae08d3ba5a6..05dfee273d8 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -18,11 +18,12 @@ #include "Util.h" #include "Common.h" -#include "CompilerDefs.h" -#include "utf8.h" -#include "Errors.h" // for ASSERT -#include <stdarg.h> -#include <boost/algorithm/string/case_conv.hpp> +#include <boost/asio/ip/address.hpp> +#include <utf8.h> +#include <algorithm> +#include <sstream> +#include <cstdarg> +#include <ctime> #if TRINITY_COMPILER == TRINITY_COMPILER_GNU #include <sys/socket.h> @@ -149,7 +150,7 @@ int64 MoneyStringToMoney(const std::string& moneyString) if (gCount + sCount + cCount != 1) return 0; - uint64 amount = atoull(*itr); + uint64 amount = strtoull(*itr, nullptr, 10); if (gCount == 1) money += amount * 100 * 100; else if (sCount == 1) @@ -171,8 +172,8 @@ uint32 TimeStringToSecs(const std::string& timestring) { if (isdigit(*itr)) { - buffer*=10; - buffer+= (*itr)-'0'; + buffer *= 10; + buffer += *itr - '0'; } else { @@ -184,9 +185,9 @@ uint32 TimeStringToSecs(const std::string& timestring) case 's': multiplier = 1; break; default : return 0; //bad format } - buffer*=multiplier; - secs+=buffer; - buffer=0; + buffer *= multiplier; + secs += buffer; + buffer = 0; } } @@ -214,9 +215,9 @@ bool IsIPAddress(char const* ipaddress) if (!ipaddress) return false; - // Let the big boys do it. - // Drawback: all valid ip address formats are recognized e.g.: 12.23, 121234, 0xABCD) - return inet_addr(ipaddress) != INADDR_NONE; + boost::system::error_code error; + boost::asio::ip::address::from_string(ipaddress, error); + return !error; } /// create PID file @@ -374,6 +375,16 @@ bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str) typedef wchar_t const* const* wstrlist; +void wstrToUpper(std::wstring& str) +{ + std::transform(str.begin(), str.end(), str.begin(), wcharToUpper); +} + +void wstrToLower(std::wstring& str) +{ + std::transform(str.begin(), str.end(), str.begin(), wcharToLower); +} + std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension) { // supported only Cyrillic cases @@ -558,6 +569,7 @@ void HexStrToByteArray(std::string const& str, uint8* out, bool reverse /*= fals bool StringToBool(std::string const& str) { - std::string lowerStr = boost::algorithm::to_lower_copy(str); + std::string lowerStr = str; + std::transform(str.begin(), str.end(), lowerStr.begin(), ::tolower); return lowerStr == "1" || lowerStr == "true" || lowerStr == "yes"; } |