mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-18 11:34:16 +01:00
fix(NumberParser): tryParseHex shall not throw, but return boolean
This commit is contained in:
parent
6b324b83d4
commit
5b7fbda0cb
@ -242,7 +242,8 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',')
|
||||
if (*pStr == thSep)
|
||||
{
|
||||
if (base == 10) continue;
|
||||
throw Poco::SyntaxException("strToInt: thousand separators only allowed for base 10");
|
||||
// thousand separators only allowed for base 10
|
||||
return false;
|
||||
}
|
||||
if (result > (limitCheck / base)) return false;
|
||||
if (!safeMultiply(result, result, base)) return false;
|
||||
|
@ -98,6 +98,12 @@ void NumberParserTest::testParse()
|
||||
assertTrue (NumberParser::parseOct64("0123") == 0123);
|
||||
#endif
|
||||
|
||||
unsigned int u;
|
||||
assertFalse (NumberParser::tryParseHex("1,000", u));
|
||||
|
||||
int i;
|
||||
assertTrue (NumberParser::tryParse("1,000", i));
|
||||
|
||||
#ifndef POCO_NO_FPENVIRONMENT
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
|
@ -99,6 +99,9 @@ private:
|
||||
|
||||
assertTrue (Poco::strToInt("0", result, 010)); assertTrue (result == 0);
|
||||
assertTrue (Poco::strToInt("000", result, 010)); assertTrue (result == 0);
|
||||
|
||||
assertFalse (Poco::strToInt("1,000", result, 0x10));
|
||||
assertFalse (Poco::strToInt("ABCDEFG", result, 0x10));
|
||||
}
|
||||
|
||||
template <typename Larger, typename Smaller>
|
||||
|
Loading…
x
Reference in New Issue
Block a user