Skip to content

Commit cf39913

Browse files
committed
Merge bitcoin#25803: refactor: Drop boost/algorithm/string/replace.hpp dependency
fea75ad refactor: Drop `boost/algorithm/string/replace.hpp` dependency (Hennadii Stepanov) 857526e test: Add test case for `ReplaceAll()` function (Hennadii Stepanov) Pull request description: A new implementation of the `ReplaceAll()` seems enough for all of our purposes. ACKs for top commit: adam2k: ACK Tested fea75ad theStack: Code-review ACK fea75ad Tree-SHA512: dacfffc9d2bd1fb9f034baf8c045b1e8657b766db2f0a7f8ef7e25ee6cd888f315b0124c54aba7a29ae59186b176ef9868a8b709dc995ea215c6b4ce58e174d9
2 parents b63c24a + fea75ad commit cf39913

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/test/util_tests.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ BOOST_AUTO_TEST_CASE(util_Join)
249249
BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR");
250250
}
251251

252+
BOOST_AUTO_TEST_CASE(util_ReplaceAll)
253+
{
254+
const std::string original("A test \"%s\" string '%s'.");
255+
auto test_replaceall = [&original](const std::string& search, const std::string& substitute, const std::string& expected) {
256+
auto test = original;
257+
ReplaceAll(test, search, substitute);
258+
BOOST_CHECK_EQUAL(test, expected);
259+
};
260+
261+
test_replaceall("", "foo", original);
262+
test_replaceall(original, "foo", "foo");
263+
test_replaceall("%s", "foo", "A test \"foo\" string 'foo'.");
264+
test_replaceall("\"", "foo", "A test foo%sfoo string '%s'.");
265+
test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo.");
266+
}
267+
252268
BOOST_AUTO_TEST_CASE(util_TrimString)
253269
{
254270
BOOST_CHECK_EQUAL(TrimString(" foo bar "), "foo bar");

src/util/string.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
#include <util/string.h>
66

7-
#include <boost/algorithm/string/replace.hpp>
8-
7+
#include <regex>
98
#include <string>
9+
#include <utility>
1010

11-
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute)
11+
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute)
1212
{
13-
boost::replace_all(in_out, search, substitute);
13+
if (search.empty()) return;
14+
in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute);
1415
}

src/util/string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <string_view>
1818
#include <vector>
1919

20-
void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute);
20+
void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute);
2121

2222
[[nodiscard]] inline std::vector<std::string> SplitString(std::string_view str, char sep)
2323
{

test/lint/lint-includes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"src/minisketch/",
2222
]
2323

24-
EXPECTED_BOOST_INCLUDES = ["boost/algorithm/string/replace.hpp",
25-
"boost/date_time/posix_time/posix_time.hpp",
24+
EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp",
2625
"boost/multi_index/hashed_index.hpp",
2726
"boost/multi_index/ordered_index.hpp",
2827
"boost/multi_index/sequenced_index.hpp",

0 commit comments

Comments
 (0)