From d7a98bf4030e57360c179e09df2a136fdbf10921 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Sun, 3 Jun 2018 16:19:19 -0500 Subject: [PATCH] remove global scope for int types --- Foundation/include/Poco/NumericString.h | 26 ++++++++++++------------- Foundation/src/NumericString.cpp | 4 ++++ Foundation/testsuite/src/StringTest.cpp | 4 ++-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Foundation/include/Poco/NumericString.h b/Foundation/include/Poco/NumericString.h index 464e34c7f..aa6369425 100644 --- a/Foundation/include/Poco/NumericString.h +++ b/Foundation/include/Poco/NumericString.h @@ -101,14 +101,14 @@ inline bool isIntOverflow(From val) if (std::numeric_limits::is_signed) { ret = (!std::numeric_limits::is_signed && - (::uintmax_t)val > (::uintmax_t)INTMAX_MAX) || - (::intmax_t)val < (::intmax_t)std::numeric_limits::min() || - (::intmax_t)val > (::intmax_t)std::numeric_limits::max(); + (uintmax_t)val > (uintmax_t)INTMAX_MAX) || + (intmax_t)val < (intmax_t)std::numeric_limits::min() || + (intmax_t)val > (intmax_t)std::numeric_limits::max(); } else { ret = isNegative(val) || - (::uintmax_t)val > (::uintmax_t)std::numeric_limits::max(); + (uintmax_t)val > (uintmax_t)std::numeric_limits::max(); } return ret; } @@ -192,7 +192,7 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',') // all numbers are parsed as positive; the sign // for negative numbers is adjusted after parsing - ::uintmax_t limitCheck = std::numeric_limits::max(); + uintmax_t limitCheck = std::numeric_limits::max(); if (negative) { poco_assert_dbg(std::numeric_limits::is_signed); @@ -200,16 +200,16 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',') // taken into account; // to avoid overflow for the largest int size, // we resort to FPEnvironment::copySign() (ie. floating-point) - if (sizeof(I) == sizeof(::intmax_t)) - limitCheck = static_cast<::uintmax_t>(FPEnvironment::copySign(static_cast(std::numeric_limits::min()), 1)); + if (sizeof(I) == sizeof(intmax_t)) + limitCheck = static_cast(FPEnvironment::copySign(static_cast(std::numeric_limits::min()), 1)); else { - ::intmax_t i = std::numeric_limits::min(); + intmax_t i = std::numeric_limits::min(); limitCheck = -i; } } - ::uintmax_t result = 0; + uintmax_t result = 0; for (; *pStr != '\0'; ++pStr) { if (result > (limitCheck / base)) return false; @@ -272,11 +272,11 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',') if (negative && (base == 10)) { poco_assert_dbg(std::numeric_limits::is_signed); - ::intmax_t i; - if (sizeof(I) == sizeof(::intmax_t)) - i = static_cast<::intmax_t>(FPEnvironment::copySign(static_cast(result), -1)); + intmax_t i; + if (sizeof(I) == sizeof(intmax_t)) + i = static_cast(FPEnvironment::copySign(static_cast(result), -1)); else - i = static_cast<::intmax_t>(-result); + i = static_cast(-result); if (isIntOverflow(i)) return false; outResult = static_cast(i); } diff --git a/Foundation/src/NumericString.cpp b/Foundation/src/NumericString.cpp index 14072dfcf..3c2c4c8c8 100644 --- a/Foundation/src/NumericString.cpp +++ b/Foundation/src/NumericString.cpp @@ -58,7 +58,11 @@ void pad(std::string& str, int precision, int width, char prefix = ' ', char dec std::string::size_type frac = str.length() - decSepPos - 1; std::string::size_type ePos = str.find_first_of("eE"); +#ifdef POCO_ENABLE_CPP11 + std::unique_ptr eStr; +#else std::auto_ptr eStr; +#endif if (ePos != std::string::npos) { eStr.reset(new std::string(str.substr(ePos, std::string::npos))); diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp index ea89e5fa0..48a265a88 100644 --- a/Foundation/testsuite/src/StringTest.cpp +++ b/Foundation/testsuite/src/StringTest.cpp @@ -612,7 +612,7 @@ void StringTest::testStringToFloat() assertTrue (FPEnvironment::isInfinite(strToFloat("-inf"))); assertTrue (FPEnvironment::isInfinite(strToFloat("infinity", "infinity"))); assertTrue (FPEnvironment::isInfinite(strToFloat("-infinity", "infinity"))); - assertTrue (FPEnvironment::isInfinite(strToFloat("Inf"))); + assertTrue (!FPEnvironment::isInfinite(strToFloat("abc"))); assertTrue (FPEnvironment::isInfinite(strToFloat("Inf", "Inf"))); } @@ -770,7 +770,7 @@ void StringTest::testStringToDouble() assertTrue (FPEnvironment::isInfinite(strToDouble("-inf"))); assertTrue (FPEnvironment::isInfinite(strToDouble("infinity", "infinity"))); assertTrue (FPEnvironment::isInfinite(strToDouble("-infinity", "infinity"))); - assertTrue (FPEnvironment::isInfinite(strToDouble("Inf"))); + assertTrue (!FPEnvironment::isInfinite(strToDouble("abc"))); assertTrue (FPEnvironment::isInfinite(strToDouble("Inf", "Inf"))); }