mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
fix(strToInt): thousand separator regression #3580
This commit is contained in:
@@ -45,7 +45,6 @@ typedef Poco::Int64 intmax_t;
|
|||||||
#pragma warning(disable : 4146)
|
#pragma warning(disable : 4146)
|
||||||
#endif // POCO_COMPILER_MSVC
|
#endif // POCO_COMPILER_MSVC
|
||||||
|
|
||||||
|
|
||||||
// binary numbers are supported, thus 64 (bits) + 1 (string terminating zero)
|
// binary numbers are supported, thus 64 (bits) + 1 (string terminating zero)
|
||||||
#define POCO_MAX_INT_STRING_LEN 65
|
#define POCO_MAX_INT_STRING_LEN 65
|
||||||
// value from strtod.cc (double_conversion::kMaxSignificantDecimalDigits)
|
// value from strtod.cc (double_conversion::kMaxSignificantDecimalDigits)
|
||||||
@@ -235,6 +234,11 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',')
|
|||||||
unsigned char add = 0;
|
unsigned char add = 0;
|
||||||
for (; *pStr != '\0'; ++pStr)
|
for (; *pStr != '\0'; ++pStr)
|
||||||
{
|
{
|
||||||
|
if (*pStr == thSep)
|
||||||
|
{
|
||||||
|
if (base == 10) continue;
|
||||||
|
throw Poco::SyntaxException("strToInt: thousand separators only allowed for base 10");
|
||||||
|
}
|
||||||
if (result > (limitCheck / base)) return false;
|
if (result > (limitCheck / base)) return false;
|
||||||
if (!safeMultiply(result, result, base)) return false;
|
if (!safeMultiply(result, result, base)) return false;
|
||||||
switch (*pStr)
|
switch (*pStr)
|
||||||
@@ -259,17 +263,6 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',')
|
|||||||
add = (*pStr - 'A') + 10;
|
add = (*pStr - 'A') + 10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.':
|
|
||||||
if ((base == 10) && (thSep == '.')) break;
|
|
||||||
else return false;
|
|
||||||
|
|
||||||
case ',':
|
|
||||||
if ((base == 10) && (thSep == ',')) break;
|
|
||||||
else return false;
|
|
||||||
|
|
||||||
case ' ':
|
|
||||||
if ((base == 10) && (thSep == ' ')) break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ void NumberParserTest::testParse()
|
|||||||
{
|
{
|
||||||
char ts = sep[i];
|
char ts = sep[i];
|
||||||
|
|
||||||
assertTrue (NumberParser::parse("123") == 123);
|
assertEqual (NumberParser::parse("123"), 123);
|
||||||
assertTrue (NumberParser::parse(format("123%c456", ts), ts) == 123456);
|
assertEqual (NumberParser::parse(format("123%c456", ts), ts), 123456);
|
||||||
assertTrue (NumberParser::parse(format("1%c234%c567", ts, ts), ts) == 1234567);
|
assertEqual (NumberParser::parse(format("1%c234%c567", ts, ts), ts), 1234567);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue (NumberParser::parse("+123") == 123);
|
assertTrue (NumberParser::parse("+123") == 123);
|
||||||
|
|||||||
Reference in New Issue
Block a user