Skip to content

Commit fa9d72a

Browse files
author
MarcoFalke
committed
Remove unused ParseDouble and ParsePrechecks
1 parent fa3cd28 commit fa9d72a

File tree

4 files changed

+0
-61
lines changed

4 files changed

+0
-61
lines changed

src/test/fuzz/parse_numbers.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ FUZZ_TARGET(parse_numbers)
1414

1515
(void)ParseMoney(random_string);
1616

17-
double d;
18-
(void)ParseDouble(random_string, &d);
19-
2017
uint8_t u8;
2118
(void)ParseUInt8(random_string, &u8);
2219

src/test/util_tests.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,32 +1730,6 @@ BOOST_AUTO_TEST_CASE(test_ParseUInt64)
17301730
BOOST_CHECK(!ParseUInt64("-1234", &n));
17311731
}
17321732

1733-
BOOST_AUTO_TEST_CASE(test_ParseDouble)
1734-
{
1735-
double n;
1736-
// Valid values
1737-
BOOST_CHECK(ParseDouble("1234", nullptr));
1738-
BOOST_CHECK(ParseDouble("0", &n) && n == 0.0);
1739-
BOOST_CHECK(ParseDouble("1234", &n) && n == 1234.0);
1740-
BOOST_CHECK(ParseDouble("01234", &n) && n == 1234.0); // no octal
1741-
BOOST_CHECK(ParseDouble("2147483647", &n) && n == 2147483647.0);
1742-
BOOST_CHECK(ParseDouble("-2147483648", &n) && n == -2147483648.0);
1743-
BOOST_CHECK(ParseDouble("-1234", &n) && n == -1234.0);
1744-
BOOST_CHECK(ParseDouble("1e6", &n) && n == 1e6);
1745-
BOOST_CHECK(ParseDouble("-1e6", &n) && n == -1e6);
1746-
// Invalid values
1747-
BOOST_CHECK(!ParseDouble("", &n));
1748-
BOOST_CHECK(!ParseDouble(" 1", &n)); // no padding inside
1749-
BOOST_CHECK(!ParseDouble("1 ", &n));
1750-
BOOST_CHECK(!ParseDouble("1a", &n));
1751-
BOOST_CHECK(!ParseDouble("aap", &n));
1752-
BOOST_CHECK(!ParseDouble("0x1", &n)); // no hex
1753-
BOOST_CHECK(!ParseDouble(STRING_WITH_EMBEDDED_NULL_CHAR, &n));
1754-
// Overflow and underflow
1755-
BOOST_CHECK(!ParseDouble("-1e10000", nullptr));
1756-
BOOST_CHECK(!ParseDouble("1e10000", nullptr));
1757-
}
1758-
17591733
BOOST_AUTO_TEST_CASE(test_FormatParagraph)
17601734
{
17611735
BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), "");

src/util/strencodings.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,6 @@ bool ParseIntegral(const std::string& str, T* out)
302302
}
303303
}; // namespace
304304

305-
[[nodiscard]] static bool ParsePrechecks(const std::string& str)
306-
{
307-
if (str.empty()) // No empty string allowed
308-
return false;
309-
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size()-1]))) // No padding allowed
310-
return false;
311-
if (!ValidAsCString(str)) // No embedded NUL characters allowed
312-
return false;
313-
return true;
314-
}
315-
316305
bool ParseInt32(const std::string& str, int32_t* out)
317306
{
318307
return ParseIntegral<int32_t>(str, out);
@@ -343,20 +332,6 @@ bool ParseUInt64(const std::string& str, uint64_t* out)
343332
return ParseIntegral<uint64_t>(str, out);
344333
}
345334

346-
bool ParseDouble(const std::string& str, double *out)
347-
{
348-
if (!ParsePrechecks(str))
349-
return false;
350-
if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed
351-
return false;
352-
std::istringstream text(str);
353-
text.imbue(std::locale::classic());
354-
double result;
355-
text >> result;
356-
if(out) *out = result;
357-
return text.eof() && !text.fail();
358-
}
359-
360335
std::string FormatParagraph(const std::string& in, size_t width, size_t indent)
361336
{
362337
std::stringstream out;

src/util/strencodings.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,6 @@ std::optional<T> ToIntegral(const std::string& str)
158158
*/
159159
[[nodiscard]] bool ParseUInt64(const std::string& str, uint64_t *out);
160160

161-
/**
162-
* Convert string to double with strict parse error feedback.
163-
* @returns true if the entire string could be parsed as valid double,
164-
* false if not the entire string could be parsed or when overflow or underflow occurred.
165-
*/
166-
[[nodiscard]] bool ParseDouble(const std::string& str, double *out);
167-
168161
/**
169162
* Convert a span of bytes to a lower-case hexadecimal string.
170163
*/

0 commit comments

Comments
 (0)