mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-03 12:58:03 +01:00
remove global scope for int types
This commit is contained in:
parent
b30683fd6d
commit
d7a98bf403
@ -101,14 +101,14 @@ inline bool isIntOverflow(From val)
|
|||||||
if (std::numeric_limits<To>::is_signed)
|
if (std::numeric_limits<To>::is_signed)
|
||||||
{
|
{
|
||||||
ret = (!std::numeric_limits<From>::is_signed &&
|
ret = (!std::numeric_limits<From>::is_signed &&
|
||||||
(::uintmax_t)val > (::uintmax_t)INTMAX_MAX) ||
|
(uintmax_t)val > (uintmax_t)INTMAX_MAX) ||
|
||||||
(::intmax_t)val < (::intmax_t)std::numeric_limits<To>::min() ||
|
(intmax_t)val < (intmax_t)std::numeric_limits<To>::min() ||
|
||||||
(::intmax_t)val > (::intmax_t)std::numeric_limits<To>::max();
|
(intmax_t)val > (intmax_t)std::numeric_limits<To>::max();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = isNegative(val) ||
|
ret = isNegative(val) ||
|
||||||
(::uintmax_t)val > (::uintmax_t)std::numeric_limits<To>::max();
|
(uintmax_t)val > (uintmax_t)std::numeric_limits<To>::max();
|
||||||
}
|
}
|
||||||
return ret;
|
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
|
// all numbers are parsed as positive; the sign
|
||||||
// for negative numbers is adjusted after parsing
|
// for negative numbers is adjusted after parsing
|
||||||
::uintmax_t limitCheck = std::numeric_limits<I>::max();
|
uintmax_t limitCheck = std::numeric_limits<I>::max();
|
||||||
if (negative)
|
if (negative)
|
||||||
{
|
{
|
||||||
poco_assert_dbg(std::numeric_limits<I>::is_signed);
|
poco_assert_dbg(std::numeric_limits<I>::is_signed);
|
||||||
@ -200,16 +200,16 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',')
|
|||||||
// taken into account;
|
// taken into account;
|
||||||
// to avoid overflow for the largest int size,
|
// to avoid overflow for the largest int size,
|
||||||
// we resort to FPEnvironment::copySign() (ie. floating-point)
|
// we resort to FPEnvironment::copySign() (ie. floating-point)
|
||||||
if (sizeof(I) == sizeof(::intmax_t))
|
if (sizeof(I) == sizeof(intmax_t))
|
||||||
limitCheck = static_cast<::uintmax_t>(FPEnvironment::copySign(static_cast<double>(std::numeric_limits<I>::min()), 1));
|
limitCheck = static_cast<uintmax_t>(FPEnvironment::copySign(static_cast<double>(std::numeric_limits<I>::min()), 1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::intmax_t i = std::numeric_limits<I>::min();
|
intmax_t i = std::numeric_limits<I>::min();
|
||||||
limitCheck = -i;
|
limitCheck = -i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
::uintmax_t result = 0;
|
uintmax_t result = 0;
|
||||||
for (; *pStr != '\0'; ++pStr)
|
for (; *pStr != '\0'; ++pStr)
|
||||||
{
|
{
|
||||||
if (result > (limitCheck / base)) return false;
|
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))
|
if (negative && (base == 10))
|
||||||
{
|
{
|
||||||
poco_assert_dbg(std::numeric_limits<I>::is_signed);
|
poco_assert_dbg(std::numeric_limits<I>::is_signed);
|
||||||
::intmax_t i;
|
intmax_t i;
|
||||||
if (sizeof(I) == sizeof(::intmax_t))
|
if (sizeof(I) == sizeof(intmax_t))
|
||||||
i = static_cast<::intmax_t>(FPEnvironment::copySign(static_cast<double>(result), -1));
|
i = static_cast<intmax_t>(FPEnvironment::copySign(static_cast<double>(result), -1));
|
||||||
else
|
else
|
||||||
i = static_cast<::intmax_t>(-result);
|
i = static_cast<intmax_t>(-result);
|
||||||
if (isIntOverflow<I>(i)) return false;
|
if (isIntOverflow<I>(i)) return false;
|
||||||
outResult = static_cast<I>(i);
|
outResult = static_cast<I>(i);
|
||||||
}
|
}
|
||||||
|
@ -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 frac = str.length() - decSepPos - 1;
|
||||||
|
|
||||||
std::string::size_type ePos = str.find_first_of("eE");
|
std::string::size_type ePos = str.find_first_of("eE");
|
||||||
|
#ifdef POCO_ENABLE_CPP11
|
||||||
|
std::unique_ptr<std::string> eStr;
|
||||||
|
#else
|
||||||
std::auto_ptr<std::string> eStr;
|
std::auto_ptr<std::string> eStr;
|
||||||
|
#endif
|
||||||
if (ePos != std::string::npos)
|
if (ePos != std::string::npos)
|
||||||
{
|
{
|
||||||
eStr.reset(new std::string(str.substr(ePos, std::string::npos)));
|
eStr.reset(new std::string(str.substr(ePos, std::string::npos)));
|
||||||
|
@ -612,7 +612,7 @@ void StringTest::testStringToFloat()
|
|||||||
assertTrue (FPEnvironment::isInfinite(strToFloat("-inf")));
|
assertTrue (FPEnvironment::isInfinite(strToFloat("-inf")));
|
||||||
assertTrue (FPEnvironment::isInfinite(strToFloat("infinity", "infinity")));
|
assertTrue (FPEnvironment::isInfinite(strToFloat("infinity", "infinity")));
|
||||||
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")));
|
assertTrue (FPEnvironment::isInfinite(strToFloat("Inf", "Inf")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,7 +770,7 @@ void StringTest::testStringToDouble()
|
|||||||
assertTrue (FPEnvironment::isInfinite(strToDouble("-inf")));
|
assertTrue (FPEnvironment::isInfinite(strToDouble("-inf")));
|
||||||
assertTrue (FPEnvironment::isInfinite(strToDouble("infinity", "infinity")));
|
assertTrue (FPEnvironment::isInfinite(strToDouble("infinity", "infinity")));
|
||||||
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")));
|
assertTrue (FPEnvironment::isInfinite(strToDouble("Inf", "Inf")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user