diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index fda56ccff7819..70e2f89e0b0f8 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -249,6 +249,22 @@ BOOST_AUTO_TEST_CASE(util_Join) BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", ", op_upper), "FOO, BAR"); } +BOOST_AUTO_TEST_CASE(util_ReplaceAll) +{ + const std::string original("A test \"%s\" string '%s'."); + auto test_replaceall = [&original](const std::string& search, const std::string& substitute, const std::string& expected) { + auto test = original; + ReplaceAll(test, search, substitute); + BOOST_CHECK_EQUAL(test, expected); + }; + + test_replaceall("", "foo", original); + test_replaceall(original, "foo", "foo"); + test_replaceall("%s", "foo", "A test \"foo\" string 'foo'."); + test_replaceall("\"", "foo", "A test foo%sfoo string '%s'."); + test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo."); +} + BOOST_AUTO_TEST_CASE(util_TrimString) { BOOST_CHECK_EQUAL(TrimString(" foo bar "), "foo bar"); diff --git a/src/util/string.cpp b/src/util/string.cpp index dff782c3309f7..db6dbe4135b9d 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -4,11 +4,12 @@ #include -#include - +#include #include +#include -void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute) +void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) { - boost::replace_all(in_out, search, substitute); + if (search.empty()) return; + in_out = std::regex_replace(in_out, std::regex(std::move(search)), substitute); } diff --git a/src/util/string.h b/src/util/string.h index df20e34ae9aaa..dd4de888bbee0 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -17,7 +17,7 @@ #include #include -void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute); +void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute); [[nodiscard]] inline std::vector SplitString(std::string_view str, char sep) { diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py index afdca0d418db0..b3fa4b93034ca 100755 --- a/test/lint/lint-includes.py +++ b/test/lint/lint-includes.py @@ -21,8 +21,7 @@ "src/minisketch/", ] -EXPECTED_BOOST_INCLUDES = ["boost/algorithm/string/replace.hpp", - "boost/date_time/posix_time/posix_time.hpp", +EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp", "boost/multi_index/hashed_index.hpp", "boost/multi_index/ordered_index.hpp", "boost/multi_index/sequenced_index.hpp",