Skip to content

Commit

Permalink
Merge bitcoin#25803: refactor: Drop `boost/algorithm/string/replace.h…
Browse files Browse the repository at this point in the history
…pp` 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
  • Loading branch information
fanquake committed Aug 16, 2022
2 parents b63c24a + fea75ad commit cf39913
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,22 @@ BOOST_AUTO_TEST_CASE(util_Join)
BOOST_CHECK_EQUAL(Join<std::string>({"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");
Expand Down
9 changes: 5 additions & 4 deletions src/util/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

#include <util/string.h>

#include <boost/algorithm/string/replace.hpp>

#include <regex>
#include <string>
#include <utility>

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);
}
2 changes: 1 addition & 1 deletion src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <string_view>
#include <vector>

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<std::string> SplitString(std::string_view str, char sep)
{
Expand Down
3 changes: 1 addition & 2 deletions test/lint/lint-includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cf39913

Please sign in to comment.