Skip to content

Commit e3245f2

Browse files
committed
Removes Boost predicate.hpp dependency
This is a squashed commit that squashes the following commits: This commit removes the `boost/algorithm/string/predicate.hpp` dependenc from the project by replacing the function calls to `boost::algorithm::starts_with` `boost::algorithm::ends_with` and `all` with respectively C++11' `std::basic_string::front`, `std::basic_string::back`, `std::all_of` function calls This commit replaces `boost::algorithm::is_digit` with a locale independent isdigi function, because the use of the standard library's `isdigit` and `std::isdigit functions is discoraged in the developer notes
1 parent 0a34593 commit e3245f2

File tree

7 files changed

+39
-16
lines changed

7 files changed

+39
-16
lines changed

src/core_read.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include <version.h>
1717

1818
#include <boost/algorithm/string/classification.hpp>
19-
#include <boost/algorithm/string/predicate.hpp>
2019
#include <boost/algorithm/string/replace.hpp>
2120
#include <boost/algorithm/string/split.hpp>
2221

22+
#include <algorithm>
23+
2324
CScript ParseScript(const std::string& s)
2425
{
2526
CScript result;
@@ -54,20 +55,20 @@ CScript ParseScript(const std::string& s)
5455
{
5556
// Empty string, ignore. (boost::split given '' will return one word)
5657
}
57-
else if (all(*w, boost::algorithm::is_digit()) ||
58-
(boost::algorithm::starts_with(*w, "-") && all(std::string(w->begin()+1, w->end()), boost::algorithm::is_digit())))
58+
else if (std::all_of(w->begin(), w->end(), ::IsDigit) ||
59+
(w->front() == '-' && w->size() > 1 && std::all_of(w->begin()+1, w->end(), ::IsDigit)))
5960
{
6061
// Number
6162
int64_t n = atoi64(*w);
6263
result << n;
6364
}
64-
else if (boost::algorithm::starts_with(*w, "0x") && (w->begin()+2 != w->end()) && IsHex(std::string(w->begin()+2, w->end())))
65+
else if (w->substr(0,2) == "0x" && w->size() > 2 && IsHex(std::string(w->begin()+2, w->end())))
6566
{
6667
// Raw hex data, inserted NOT pushed onto stack:
6768
std::vector<unsigned char> raw = ParseHex(std::string(w->begin()+2, w->end()));
6869
result.insert(result.end(), raw.begin(), raw.end());
6970
}
70-
else if (w->size() >= 2 && boost::algorithm::starts_with(*w, "'") && boost::algorithm::ends_with(*w, "'"))
71+
else if (w->size() >= 2 && w->front() == '\'' && w->back() == '\'')
7172
{
7273
// Single-quoted string, pushed as data. NOTE: this is poor-man's
7374
// parsing, spaces/tabs/newlines in single-quoted strings won't work.

src/netbase.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#endif
2121

2222
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
23-
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
2423

2524
#if !defined(MSG_NOSIGNAL)
2625
#define MSG_NOSIGNAL 0
@@ -121,8 +120,7 @@ bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nM
121120
std::string strHost(pszName);
122121
if (strHost.empty())
123122
return false;
124-
if (boost::algorithm::starts_with(strHost, "[") && boost::algorithm::ends_with(strHost, "]"))
125-
{
123+
if (strHost.front() == '[' && strHost.back() == ']') {
126124
strHost = strHost.substr(1, strHost.size() - 2);
127125
}
128126

src/test/util_tests.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,21 @@ BOOST_AUTO_TEST_CASE(gettime)
806806
BOOST_CHECK((GetTime() & ~0xFFFFFFFFLL) == 0);
807807
}
808808

809+
BOOST_AUTO_TEST_CASE(test_IsDigit)
810+
{
811+
BOOST_CHECK_EQUAL(IsDigit('0'), true);
812+
BOOST_CHECK_EQUAL(IsDigit('1'), true);
813+
BOOST_CHECK_EQUAL(IsDigit('8'), true);
814+
BOOST_CHECK_EQUAL(IsDigit('9'), true);
815+
816+
BOOST_CHECK_EQUAL(IsDigit('0' - 1), false);
817+
BOOST_CHECK_EQUAL(IsDigit('9' + 1), false);
818+
BOOST_CHECK_EQUAL(IsDigit(0), false);
819+
BOOST_CHECK_EQUAL(IsDigit(1), false);
820+
BOOST_CHECK_EQUAL(IsDigit(8), false);
821+
BOOST_CHECK_EQUAL(IsDigit(9), false);
822+
}
823+
809824
BOOST_AUTO_TEST_CASE(test_ParseInt32)
810825
{
811826
int32_t n;

src/utilstrencodings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
473473
/* pass single 0 */
474474
++ptr;
475475
} else if (val[ptr] >= '1' && val[ptr] <= '9') {
476-
while (ptr < end && val[ptr] >= '0' && val[ptr] <= '9') {
476+
while (ptr < end && IsDigit(val[ptr])) {
477477
if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
478478
return false; /* overflow */
479479
++ptr;
@@ -483,9 +483,9 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
483483
if (ptr < end && val[ptr] == '.')
484484
{
485485
++ptr;
486-
if (ptr < end && val[ptr] >= '0' && val[ptr] <= '9')
486+
if (ptr < end && IsDigit(val[ptr]))
487487
{
488-
while (ptr < end && val[ptr] >= '0' && val[ptr] <= '9') {
488+
while (ptr < end && IsDigit(val[ptr])) {
489489
if (!ProcessMantissaDigit(val[ptr], mantissa, mantissa_tzeros))
490490
return false; /* overflow */
491491
++ptr;
@@ -502,8 +502,8 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out)
502502
exponent_sign = true;
503503
++ptr;
504504
}
505-
if (ptr < end && val[ptr] >= '0' && val[ptr] <= '9') {
506-
while (ptr < end && val[ptr] >= '0' && val[ptr] <= '9') {
505+
if (ptr < end && IsDigit(val[ptr])) {
506+
while (ptr < end && IsDigit(val[ptr])) {
507507
if (exponent > (UPPER_BOUND / 10LL))
508508
return false; /* overflow */
509509
exponent = exponent * 10 + val[ptr] - '0';

src/utilstrencodings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ int64_t atoi64(const char* psz);
6161
int64_t atoi64(const std::string& str);
6262
int atoi(const std::string& str);
6363

64+
/**
65+
* Tests if the given character is a decimal digit.
66+
* @param[in] c character to test
67+
* @return true if the argument is a decimal digit; otherwise false.
68+
*/
69+
constexpr bool IsDigit(char c)
70+
{
71+
return c >= '0' && c <= '9';
72+
}
73+
6474
/**
6575
* Convert string to signed 32-bit integer with strict parse error feedback.
6676
* @returns true if the entire string could be parsed as valid integer,

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,13 @@ UniValue importwallet(const JSONRPCRequest& request)
585585
std::string strLabel;
586586
bool fLabel = true;
587587
for (unsigned int nStr = 2; nStr < vstr.size(); nStr++) {
588-
if (boost::algorithm::starts_with(vstr[nStr], "#"))
588+
if (vstr[nStr].front() == '#')
589589
break;
590590
if (vstr[nStr] == "change=1")
591591
fLabel = false;
592592
if (vstr[nStr] == "reserve=1")
593593
fLabel = false;
594-
if (boost::algorithm::starts_with(vstr[nStr], "label=")) {
594+
if (vstr[nStr].substr(0,6) == "label=") {
595595
strLabel = DecodeDumpString(vstr[nStr].substr(6));
596596
fLabel = true;
597597
}

test/lint/lint-includes.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ EXPECTED_BOOST_INCLUDES=(
4949
boost/algorithm/string.hpp
5050
boost/algorithm/string/case_conv.hpp
5151
boost/algorithm/string/classification.hpp
52-
boost/algorithm/string/predicate.hpp
5352
boost/algorithm/string/replace.hpp
5453
boost/algorithm/string/split.hpp
5554
boost/bind.hpp

0 commit comments

Comments
 (0)