From 1f9dfabef64121c5ea030f5dbaaaf2a6af706eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Thu, 20 Aug 2026 13:11:34 -0700 Subject: [PATCH] refactor: use string views in `ReplaceAll` PR #25803 changed these parameters to `const std::string&` for `std::regex_replace()`. The literal implementation no longer needs owned strings, so restore the original `std::string_view` interface. --- src/test/util_tests.cpp | 2 +- src/util/string.cpp | 3 ++- src/util/string.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index a7ba38b6d04..413236f4552 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(util_Join) BOOST_AUTO_TEST_CASE(util_ReplaceAll) { const std::string original("A test \"%s\" string '%s'."); - auto test_replaceall{[](std::string test, const std::string& search, const std::string& substitute, const std::string& expected) { + auto test_replaceall{[](std::string test, std::string_view search, std::string_view substitute, std::string_view expected) { ReplaceAll(test, search, substitute); BOOST_CHECK_EQUAL(test, expected); }}; diff --git a/src/util/string.cpp b/src/util/string.cpp index c197076715d..3c84a487e95 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -8,9 +8,10 @@ #include #include #include +#include namespace util { -void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute) +void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute) { if (search.empty()) return; auto pos{in_out.find(search)}; diff --git a/src/util/string.h b/src/util/string.h index 0963c12d698..265bf987e50 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -99,7 +99,7 @@ struct ConstevalFormatString { }; /// Replace every non-overlapping occurrence of `search` with `substitute`, treating both literally; the replacement text is not searched again. -void ReplaceAll(std::string& in_out, const std::string& search, const std::string& substitute); +void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute); /** Split a string on any char found in separators, returning a vector. *