fixed GH #1462: AbstractConfiguration::getUInt does not parse hex numbers

This commit is contained in:
Guenter Obiltschnig 2016-10-24 09:41:49 +02:00
parent aa9987e0bc
commit df855c88b7
3 changed files with 13 additions and 10 deletions

View File

@ -346,7 +346,7 @@ protected:
/// implementation throws a Poco::NotImplementedException.
static int parseInt(const std::string& value);
static int parseUInt(const std::string& value);
static unsigned parseUInt(const std::string& value);
#if defined(POCO_HAVE_INT64)

View File

@ -147,7 +147,7 @@ unsigned AbstractConfiguration::getUInt(const std::string& key) const
std::string value;
if (getRaw(key, value))
return NumberParser::parseUnsigned(internalExpand(value));
return parseUInt(internalExpand(value));
else
throw NotFoundException(key);
}
@ -159,7 +159,7 @@ unsigned AbstractConfiguration::getUInt(const std::string& key, unsigned default
std::string value;
if (getRaw(key, value))
return NumberParser::parseUnsigned(internalExpand(value));
return parseUInt(internalExpand(value));
else
return defaultValue;
}
@ -174,7 +174,7 @@ Int64 AbstractConfiguration::getInt64(const std::string& key) const
std::string value;
if (getRaw(key, value))
return NumberParser::parse64(internalExpand(value));
return parseInt64(internalExpand(value));
else
throw NotFoundException(key);
}
@ -186,7 +186,7 @@ Int64 AbstractConfiguration::getInt64(const std::string& key, Int64 defaultValue
std::string value;
if (getRaw(key, value))
return NumberParser::parse64(internalExpand(value));
return parseInt64(internalExpand(value));
else
return defaultValue;
}
@ -198,7 +198,7 @@ UInt64 AbstractConfiguration::getUInt64(const std::string& key) const
std::string value;
if (getRaw(key, value))
return NumberParser::parseUnsigned64(internalExpand(value));
return parseUInt64(internalExpand(value));
else
throw NotFoundException(key);
}
@ -210,7 +210,7 @@ UInt64 AbstractConfiguration::getUInt64(const std::string& key, UInt64 defaultVa
std::string value;
if (getRaw(key, value))
return NumberParser::parseUnsigned64(internalExpand(value));
return parseUInt64(internalExpand(value));
else
return defaultValue;
}
@ -462,13 +462,13 @@ std::string AbstractConfiguration::uncheckedExpand(const std::string& value) con
int AbstractConfiguration::parseInt(const std::string& value)
{
if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0))
return NumberParser::parseHex(value);
return static_cast<int>(NumberParser::parseHex(value));
else
return NumberParser::parse(value);
}
int AbstractConfiguration::parseUInt(const std::string& value)
unsigned AbstractConfiguration::parseUInt(const std::string& value)
{
if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0))
return NumberParser::parseHex(value);
@ -480,7 +480,7 @@ int AbstractConfiguration::parseUInt(const std::string& value)
Int64 AbstractConfiguration::parseInt64(const std::string& value)
{
if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0))
return NumberParser::parseHex64(value);
return static_cast<Int64>(NumberParser::parseHex64(value));
else
return NumberParser::parse64(value);
}

View File

@ -89,6 +89,7 @@ void AbstractConfigurationTest::testGetInt()
assert (pConf->getInt("prop4.int1") == 42);
assert (pConf->getInt("prop4.int2") == -42);
assert (pConf->getInt("prop4.hex") == 0x1f);
assert (pConf->getUInt("prop4.hex") == 0x1f);
assert (pConf->getInt("ref2") == 42);
try
@ -114,6 +115,8 @@ void AbstractConfigurationTest::testGetInt64()
assert (pConf->getInt64("prop4.bigint1") == std::numeric_limits<Int64>::max());
assert (pConf->getInt64("prop4.bigint2") == std::numeric_limits<Int64>::min());
assert (pConf->getUInt64("prop4.biguint") == std::numeric_limits<UInt64>::max());
assert (pConf->getInt64("prop4.hex") == 0x1f);
assert (pConf->getUInt64("prop4.hex") == 0x1f);
assert (pConf->getInt64("ref2") == 42);
try