mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
Remove unused ParseDouble and ParsePrechecks
This commit is contained in:
parent
fa3cd28535
commit
fa9d72a794
@ -14,9 +14,6 @@ FUZZ_TARGET(parse_numbers)
|
||||
|
||||
(void)ParseMoney(random_string);
|
||||
|
||||
double d;
|
||||
(void)ParseDouble(random_string, &d);
|
||||
|
||||
uint8_t u8;
|
||||
(void)ParseUInt8(random_string, &u8);
|
||||
|
||||
|
@ -1730,32 +1730,6 @@ BOOST_AUTO_TEST_CASE(test_ParseUInt64)
|
||||
BOOST_CHECK(!ParseUInt64("-1234", &n));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ParseDouble)
|
||||
{
|
||||
double n;
|
||||
// Valid values
|
||||
BOOST_CHECK(ParseDouble("1234", nullptr));
|
||||
BOOST_CHECK(ParseDouble("0", &n) && n == 0.0);
|
||||
BOOST_CHECK(ParseDouble("1234", &n) && n == 1234.0);
|
||||
BOOST_CHECK(ParseDouble("01234", &n) && n == 1234.0); // no octal
|
||||
BOOST_CHECK(ParseDouble("2147483647", &n) && n == 2147483647.0);
|
||||
BOOST_CHECK(ParseDouble("-2147483648", &n) && n == -2147483648.0);
|
||||
BOOST_CHECK(ParseDouble("-1234", &n) && n == -1234.0);
|
||||
BOOST_CHECK(ParseDouble("1e6", &n) && n == 1e6);
|
||||
BOOST_CHECK(ParseDouble("-1e6", &n) && n == -1e6);
|
||||
// Invalid values
|
||||
BOOST_CHECK(!ParseDouble("", &n));
|
||||
BOOST_CHECK(!ParseDouble(" 1", &n)); // no padding inside
|
||||
BOOST_CHECK(!ParseDouble("1 ", &n));
|
||||
BOOST_CHECK(!ParseDouble("1a", &n));
|
||||
BOOST_CHECK(!ParseDouble("aap", &n));
|
||||
BOOST_CHECK(!ParseDouble("0x1", &n)); // no hex
|
||||
BOOST_CHECK(!ParseDouble(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
|
||||
// Overflow and underflow
|
||||
BOOST_CHECK(!ParseDouble("-1e10000", nullptr));
|
||||
BOOST_CHECK(!ParseDouble("1e10000", nullptr));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_FormatParagraph)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), "");
|
||||
|
@ -302,17 +302,6 @@ bool ParseIntegral(const std::string& str, T* out)
|
||||
}
|
||||
}; // namespace
|
||||
|
||||
[[nodiscard]] static bool ParsePrechecks(const std::string& str)
|
||||
{
|
||||
if (str.empty()) // No empty string allowed
|
||||
return false;
|
||||
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size()-1]))) // No padding allowed
|
||||
return false;
|
||||
if (!ValidAsCString(str)) // No embedded NUL characters allowed
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseInt32(const std::string& str, int32_t* out)
|
||||
{
|
||||
return ParseIntegral<int32_t>(str, out);
|
||||
@ -343,20 +332,6 @@ bool ParseUInt64(const std::string& str, uint64_t* out)
|
||||
return ParseIntegral<uint64_t>(str, out);
|
||||
}
|
||||
|
||||
bool ParseDouble(const std::string& str, double *out)
|
||||
{
|
||||
if (!ParsePrechecks(str))
|
||||
return false;
|
||||
if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
|
||||
return false;
|
||||
std::istringstream text(str);
|
||||
text.imbue(std::locale::classic());
|
||||
double result;
|
||||
text >> result;
|
||||
if(out) *out = result;
|
||||
return text.eof() && !text.fail();
|
||||
}
|
||||
|
||||
std::string FormatParagraph(const std::string& in, size_t width, size_t indent)
|
||||
{
|
||||
std::stringstream out;
|
||||
|
@ -158,13 +158,6 @@ std::optional<T> ToIntegral(const std::string& str)
|
||||
*/
|
||||
[[nodiscard]] bool ParseUInt64(const std::string& str, uint64_t *out);
|
||||
|
||||
/**
|
||||
* Convert string to double with strict parse error feedback.
|
||||
* @returns true if the entire string could be parsed as valid double,
|
||||
* false if not the entire string could be parsed or when overflow or underflow occurred.
|
||||
*/
|
||||
[[nodiscard]] bool ParseDouble(const std::string& str, double *out);
|
||||
|
||||
/**
|
||||
* Convert a span of bytes to a lower-case hexadecimal string.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user