refactor: Remove unused ParsePrechecks from ParseIntegral

Also:
* Remove redundant {} from return statement
* Add missing failing c-string test case and "-" and "+" strings
* Add missing failing test cases for non-int32_t integral types
This commit is contained in:
MarcoFalke
2021-10-01 17:33:35 +02:00
parent 35a31d5f7e
commit fa3cd28535
3 changed files with 41 additions and 28 deletions

View File

@@ -281,16 +281,11 @@ std::string DecodeBase32(const std::string& str, bool* pf_invalid)
return std::string((const char*)vchRet.data(), vchRet.size());
}
[[nodiscard]] static bool ParsePrechecks(const std::string&);
namespace {
template <typename T>
bool ParseIntegral(const std::string& str, T* out)
{
static_assert(std::is_integral<T>::value);
if (!ParsePrechecks(str)) {
return false;
}
// Replicate the exact behavior of strtol/strtoll/strtoul/strtoull when
// handling leading +/- for backwards compatibility.
if (str.length() >= 2 && str[0] == '+' && str[1] == '-') {